2
0

⚗️ Implement chat API

This commit is contained in:
Baptiste Arnaud
2022-11-29 10:02:40 +01:00
parent 49ba434350
commit bf0d0c2475
122 changed files with 5075 additions and 292 deletions

View File

@ -79,7 +79,7 @@ export const importTypebotInDatabase = async (
...updates,
}
await prisma.typebot.create({
data: typebot,
data: parseCreateTypebot(typebot),
})
return prisma.publicTypebot.create({
data: parseTypebotToPublicTypebot(
@ -163,7 +163,7 @@ export const createTypebots = async (partialTypebots: Partial<Typebot>[]) => {
}
})
await prisma.typebot.createMany({
data: typebotsWithId.map(parseTestTypebot),
data: typebotsWithId.map(parseTestTypebot).map(parseCreateTypebot),
})
return prisma.publicTypebot.createMany({
data: typebotsWithId.map((t) =>
@ -177,7 +177,7 @@ export const updateTypebot = async (
) => {
await prisma.typebot.updateMany({
where: { id: partialTypebot.id },
data: partialTypebot,
data: parseUpdateTypebot(partialTypebot),
})
return prisma.publicTypebot.updateMany({
where: { typebotId: partialTypebot.id },
@ -194,3 +194,19 @@ export const updateWorkspace = async (
data,
})
}
const parseCreateTypebot = (typebot: Typebot) => ({
...typebot,
resultsTablePreferences:
typebot.resultsTablePreferences === null
? Prisma.DbNull
: typebot.resultsTablePreferences,
})
const parseUpdateTypebot = (typebot: Partial<Typebot>) => ({
...typebot,
resultsTablePreferences:
typebot.resultsTablePreferences === null
? Prisma.DbNull
: typebot.resultsTablePreferences,
})