Delete votes first

This commit is contained in:
Luke Vella 2024-10-20 09:53:47 +01:00
parent 13e99a9594
commit f7400f5aad
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C

View file

@ -59,9 +59,13 @@ export const user = router({
where: { userId: ctx.user.id },
});
const pollIds = polls.map((poll) => poll.id);
await tx.comment.deleteMany({
await tx.vote.deleteMany({
where: { pollId: { in: pollIds } },
});
await tx.comment.deleteMany({
where: { OR: [{ pollId: { in: pollIds } }, { userId: ctx.user.id }] },
});
await tx.option.deleteMany({
where: { pollId: { in: pollIds } },
});
@ -71,15 +75,9 @@ export const user = router({
await tx.watcher.deleteMany({
where: { OR: [{ pollId: { in: pollIds } }, { userId: ctx.user.id }] },
});
await tx.vote.deleteMany({
where: { pollId: { in: pollIds } },
});
await tx.event.deleteMany({
where: { userId: ctx.user.id },
});
await tx.comment.deleteMany({
where: { OR: [{ pollId: { in: pollIds } }, { userId: ctx.user.id }] },
});
await tx.poll.deleteMany({
where: { userId: ctx.user.id },
});