2
0
Files
bot/packages/bot-engine/queries/createResultIfNotExist.ts
2024-01-12 10:16:01 +01:00

34 lines
710 B
TypeScript

import prisma from '@typebot.io/lib/prisma'
import { TypebotInSession } from '@typebot.io/schemas'
type Props = {
resultId: string
typebot: TypebotInSession
hasStarted: boolean
isCompleted: boolean
}
export const createResultIfNotExist = async ({
resultId,
typebot,
hasStarted,
isCompleted,
}: Props) => {
const existingResult = await prisma.result.findUnique({
where: { id: resultId },
select: { id: true },
})
if (existingResult) return
return prisma.result.createMany({
data: [
{
id: resultId,
typebotId: typebot.id,
isCompleted: isCompleted ? true : false,
hasStarted,
variables: typebot.variables,
},
],
})
}