2
0

🚸 (editor) Improve typebot updatedAt detection

Make sure the database is the single source of truth
This commit is contained in:
Baptiste Arnaud
2023-02-16 20:43:28 +01:00
parent 618eb8a882
commit 4a0dd0b3dd
4 changed files with 12 additions and 7 deletions

View File

@ -94,11 +94,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
resultsTablePreferences: data.resultsTablePreferences ?? undefined,
} satisfies Prisma.TypebotUpdateInput
const { count } = await prisma.typebot.updateMany({
const updatedTypebot = await prisma.typebot.update({
where: { id: typebotId },
data: updates,
})
return res.send({ count })
return res.send({ typebot: updatedTypebot })
}
if (req.method === 'PATCH') {
@ -109,11 +110,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
})
if (!typebot) return res.status(404).send({ message: 'Typebot not found' })
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
const typebots = await prisma.typebot.updateMany({
const updatedTypebot = await prisma.typebot.update({
where: { id: typebotId },
data,
})
return res.send({ typebots })
return res.send({ typebot: updatedTypebot })
}
return methodNotAllowed(res)
}