2
0

feat(editor): Restore published version button

Had to migrate webhooks into a standalone table
This commit is contained in:
Baptiste Arnaud
2022-03-01 07:13:09 +01:00
parent 0df719d531
commit e17a1a0869
46 changed files with 578 additions and 348 deletions

View File

@ -1,8 +1,6 @@
import {
Block,
defaultSettings,
defaultTheme,
PublicBlock,
PublicTypebot,
Step,
Typebot,
@ -12,12 +10,13 @@ import { readFileSync } from 'fs'
const prisma = new PrismaClient()
export const teardownDatabase = () => {
export const teardownDatabase = async () => {
try {
return prisma.user.delete({
await prisma.user.delete({
where: { id: 'user' },
})
} catch {}
return
}
export const setupDatabase = () => createUser()
@ -32,6 +31,15 @@ export const createUser = () =>
},
})
export const createWebhook = (typebotId: string) =>
prisma.webhook.create({
data: {
id: 'webhook1',
typebotId: typebotId,
method: 'GET',
},
})
export const createTypebots = async (partialTypebots: Partial<Typebot>[]) => {
await prisma.typebot.createMany({
data: partialTypebots.map(parseTestTypebot) as any[],
@ -49,7 +57,7 @@ const parseTypebotToPublicTypebot = (
): PublicTypebot => ({
id,
name: typebot.name,
blocks: parseBlocksToPublicBlocks(typebot.blocks),
blocks: typebot.blocks,
typebotId: typebot.id,
theme: typebot.theme,
settings: typebot.settings,
@ -57,16 +65,10 @@ const parseTypebotToPublicTypebot = (
variables: typebot.variables,
edges: typebot.edges,
customDomain: null,
createdAt: typebot.createdAt,
updatedAt: typebot.updatedAt,
})
const parseBlocksToPublicBlocks = (blocks: Block[]): PublicBlock[] =>
blocks.map((b) => ({
...b,
steps: b.steps.map((s) =>
'webhook' in s ? { ...s, webhook: s.webhook.id } : s
),
}))
const parseTestTypebot = (partialTypebot: Partial<Typebot>): Typebot => ({
id: partialTypebot.id ?? 'typebot',
folderId: null,