diff options
author | Raphael Kabo <mail@raphaelkabo.com> | 2022-11-16 16:16:23 +0000 |
---|---|---|
committer | Raphael Kabo <mail@raphaelkabo.com> | 2022-11-16 16:16:23 +0000 |
commit | e93b23db71df18480b29ed53c1b8247e7f0f83a7 (patch) | |
tree | db74310fc79c02b4de4d65d2f013833ad5af2c44 /routes.js | |
parent | b2298e4b627a3d19439bfa31071106b044c569f9 (diff) |
fix: check if event has max attendee limit
Diffstat (limited to 'routes.js')
-rwxr-xr-x | routes.js | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -1411,7 +1411,12 @@ router.post('/attendee/provision', async (req, res) => { addToLog("provisionEventAttendee", "success", "Attendee provisioned in event " + req.query.eventID); // Return the removal password and the number of free spots remaining - const freeSpots = event.maxAttendees - event.attendees.reduce((acc, a) => acc + (a.status === 'attending' ? (a.number || 1) : 0), 0); + let freeSpots; + if (event.maxAttendees !== null && event.maxAttendees !== undefined) { + freeSpots = event.maxAttendees - event.attendees.reduce((acc, a) => acc + (a.status === 'attending' ? (a.number || 1) : 0), 0); + } else { + freeSpots = undefined; + } return res.json({ removalPassword, freeSpots }); }); @@ -1432,9 +1437,12 @@ router.post('/attendevent/:eventID', async (req, res) => { return res.sendStatus(404); } // Do we have enough free spots in this event to accomodate this attendee? - const freeSpots = event.maxAttendees - event.attendees.reduce((acc, a) => acc + (a.status === 'attending' ? (a.number || 1) : 0), 0); - if (req.body.attendeeNumber > freeSpots) { - return res.sendStatus(403); + // First, check if the event has a max number of attendees + if (event.maxAttendees !== null && event.maxAttendees !== undefined) { + const freeSpots = event.maxAttendees - event.attendees.reduce((acc, a) => acc + (a.status === 'attending' ? (a.number || 1) : 0), 0); + if (req.body.attendeeNumber > freeSpots) { + return res.sendStatus(403); + } } Event.findOneAndUpdate({ id: req.params.eventID, 'attendees.removalPassword': req.body.removalPassword }, { |