feat(editor): ✨ Restore published version button
Had to migrate webhooks into a standalone table
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user