Reset legacy poll

This commit is contained in:
Luke Vella 2022-04-12 12:32:34 +01:00
parent e830d0b0f4
commit 08f2524869
3 changed files with 25 additions and 10 deletions

View file

@ -46,13 +46,7 @@ export default async function handler(
res: NextApiResponse<GetPollApiResponse>,
) {
const urlId = getQueryParam(req, "urlId");
const existingPoll = await prisma.poll.findUnique({ where: { urlId } });
if (existingPoll) {
// if the poll already exists with this id then we probably shouldn't be here
return res.status(400).end();
}
const reset = req.query.reset;
const client = await getMongoClient();
if (!client) {
@ -105,6 +99,10 @@ export default async function handler(
});
});
if (reset) {
await prisma.poll.delete({ where: { urlId: legacyPoll._id } });
}
const poll = await prisma.poll.create({
data: {
legacy: true,