Skip to content

Commit

Permalink
🐛 Reset custom domain on typebot archive
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 6, 2023
1 parent 5c31048 commit 6375a75
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions apps/builder/src/pages/api/typebots/[typebotId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
})
const typebots = await prisma.typebot.updateMany({
where: { id: typebotId },
data: { isArchived: true, publicId: null },
data: { isArchived: true, publicId: null, customDomain: null },
})
return res.send({ typebots })
}
Expand Down Expand Up @@ -101,12 +101,25 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
edges: data.edges ?? [],
} satisfies Prisma.TypebotUpdateInput

const updatedTypebot = await prisma.typebot.update({
where: { id: typebotId },
data: updates,
})

return res.send({ typebot: updatedTypebot })
try {
const updatedTypebot = await prisma.typebot.update({
where: { id: typebotId },
data: updates,
})
return res.send({ typebot: updatedTypebot })
} catch (err) {
if (err instanceof Prisma.PrismaClientKnownRequestError) {
if (err.code === 'P2002') {
return res.status(409).send({
message:
err.meta && 'target' in err.meta && Array.isArray(err.meta.target)
? `${err.meta.target[0]} already exists`
: 'Duplicate conflict',
})
}
return res.status(500).send({ message: err.message })
}
}
}

if (req.method === 'PATCH') {
Expand Down

0 comments on commit 6375a75

Please sign in to comment.