mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-06 09:59:00 +02:00
Delete votes before deleting option
This commit is contained in:
parent
2e46807846
commit
544a42edc4
1 changed files with 16 additions and 7 deletions
|
@ -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([
|
||||||
|
prisma.vote.deleteMany({
|
||||||
|
where: {
|
||||||
|
optionId: {
|
||||||
|
in: input.optionsToDelete,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
prisma.option.deleteMany({
|
||||||
where: {
|
where: {
|
||||||
pollId,
|
pollId,
|
||||||
id: {
|
id: {
|
||||||
in: input.optionsToDelete,
|
in: input.optionsToDelete,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.optionsToAdd && input.optionsToAdd.length > 0) {
|
if (input.optionsToAdd && input.optionsToAdd.length > 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue