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;
if (input.optionsToDelete && input.optionsToDelete.length > 0) {
await prisma.option.deleteMany({
where: {
pollId,
id: {
in: input.optionsToDelete,
await prisma.$transaction([
prisma.vote.deleteMany({
where: {
optionId: {
in: input.optionsToDelete,
},
},
},
});
}),
prisma.option.deleteMany({
where: {
pollId,
id: {
in: input.optionsToDelete,
},
},
}),
]);
}
if (input.optionsToAdd && input.optionsToAdd.length > 0) {