import prisma from "indite-js/lib/prisma"; import { BotInSession } from "indite-js/schemas"; type Props = { resultId: string; bot: BotInSession; hasStarted: boolean; isCompleted: boolean; }; export const createResultIfNotExist = async ({ resultId, bot, 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, botId: bot.id, isCompleted: isCompleted ? true : false, hasStarted, variables: bot.variables, }, ], }); };