Skip to content

Commit

Permalink
fix: maximum one vote per option
Browse files Browse the repository at this point in the history
  • Loading branch information
edalholt committed Nov 10, 2023
1 parent 5401485 commit df65ba0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/controllers/votation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ export async function submitVote(req: RequestWithNtnuiNo, res: Response) {
const group = req.body.group;
const voteId = req.body.voteId;
const user = await User.findById(req.ntnuiNo);
const optionIDs: string[] = req.body.optionIDs;
let optionIDs: string[] = req.body.optionIDs;

if (user) {
if (user.groups.some((membership) => membership.groupSlug == group)) {
Expand All @@ -563,6 +563,9 @@ export async function submitVote(req: RequestWithNtnuiNo, res: Response) {
return res.status(400).json({ message: "No vote provided" });
}

// Remove duplicates (maximum one vote per option)
optionIDs = [...new Set(optionIDs)];

const vote = await Votation.findById(voteId);
const assembly = await Assembly.findById(group);

Expand Down

0 comments on commit df65ba0

Please sign in to comment.