mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-28 17:56:37 +02:00
🐛 Filter deleted options from votes (#1619)
This commit is contained in:
parent
8f7aadb685
commit
ebe265ddc3
1 changed files with 32 additions and 2 deletions
|
@ -173,8 +173,23 @@ export const participants = router({
|
|||
},
|
||||
});
|
||||
|
||||
const options = await prisma.option.findMany({
|
||||
where: {
|
||||
pollId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
|
||||
const existingOptionIds = new Set(options.map((option) => option.id));
|
||||
|
||||
const validVotes = votes.filter(({ optionId }) =>
|
||||
existingOptionIds.has(optionId),
|
||||
);
|
||||
|
||||
await prisma.vote.createMany({
|
||||
data: votes.map(({ optionId, type }) => ({
|
||||
data: validVotes.map(({ optionId, type }) => ({
|
||||
optionId,
|
||||
type,
|
||||
pollId,
|
||||
|
@ -252,9 +267,24 @@ export const participants = router({
|
|||
},
|
||||
});
|
||||
|
||||
const options = await prisma.option.findMany({
|
||||
where: {
|
||||
pollId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
|
||||
const existingOptionIds = new Set(options.map((option) => option.id));
|
||||
|
||||
const validVotes = votes.filter(({ optionId }) =>
|
||||
existingOptionIds.has(optionId),
|
||||
);
|
||||
|
||||
// Create new votes
|
||||
await tx.vote.createMany({
|
||||
data: votes.map(({ optionId, type }) => ({
|
||||
data: validVotes.map(({ optionId, type }) => ({
|
||||
optionId,
|
||||
type,
|
||||
pollId,
|
||||
|
|
Loading…
Add table
Reference in a new issue