Delete votes before deleting option

This commit is contained in:
Luke Vella 2022-05-20 15:28:01 +01:00
parent 2e46807846
commit 544a42edc4

View file

@ -165,14 +165,23 @@ export const polls = createRouter()
const { pollId } = link; const { pollId } = link;
if (input.optionsToDelete && input.optionsToDelete.length > 0) { if (input.optionsToDelete && input.optionsToDelete.length > 0) {
await prisma.option.deleteMany({ await prisma.$transaction([
where: { prisma.vote.deleteMany({
pollId, where: {
id: { optionId: {
in: input.optionsToDelete, in: input.optionsToDelete,
},
}, },
}, }),
}); prisma.option.deleteMany({
where: {
pollId,
id: {
in: input.optionsToDelete,
},
},
}),
]);
} }
if (input.optionsToAdd && input.optionsToAdd.length > 0) { if (input.optionsToAdd && input.optionsToAdd.length > 0) {