summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Kabo <mail@raphaelkabo.com>2022-11-16 16:16:23 +0000
committerRaphael Kabo <mail@raphaelkabo.com>2022-11-16 16:16:23 +0000
commite93b23db71df18480b29ed53c1b8247e7f0f83a7 (patch)
treedb74310fc79c02b4de4d65d2f013833ad5af2c44
parentb2298e4b627a3d19439bfa31071106b044c569f9 (diff)
fix: check if event has max attendee limit
-rwxr-xr-xroutes.js16
-rwxr-xr-xviews/event.handlebars10
2 files changed, 19 insertions, 7 deletions
diff --git a/routes.js b/routes.js
index a3f3d87..8e0a282 100755
--- a/routes.js
+++ b/routes.js
@@ -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 }, {
diff --git a/views/event.handlebars b/views/event.handlebars
index 8c7e2e8..ff88ba5 100755
--- a/views/event.handlebars
+++ b/views/event.handlebars
@@ -582,9 +582,13 @@
axios.post('/attendee/provision', {}, { params: { eventID }})
.then((response) => {
modal.find('#removalPassword').val(response.data.removalPassword);
- modal.find('#attendeeNumber')
- .attr('data-validation-allowing', `range[1;${response.data.freeSpots}]`)
- .attr('data-validation-error-msg', `Please enter a number between 1 and ${response.data.freeSpots}`);
+ // If there is a limit on the number of attendees, the provisioned endpoint will return freeSpots;
+ // otherwise, freeSpots will be undefined.
+ if (response.data.freeSpots !== undefined) {
+ modal.find('#attendeeNumber')
+ .attr('data-validation-allowing', `range[1;${response.data.freeSpots}]`)
+ .attr('data-validation-error-msg', `Please enter a number between 1 and ${response.data.freeSpots}`);
+ }
modal.modal();
})
.catch((error) => {