diff options
author | Raphael <mail@raphaelkabo.com> | 2024-03-04 11:35:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-04 11:35:37 +0000 |
commit | 6f0721686aea7647554ad0f3ee4f6099bff4ef58 (patch) | |
tree | 50b20e89f067ccaf7121037e889881e1af1f6396 /src/routes/event.ts | |
parent | 724df500a009ec5bebe0911c59892058e74dc4e2 (diff) | |
parent | dd55bdf8fac285d3ade31542c65b57c11f061c93 (diff) |
Merge pull request #142 from lowercasename/rk/patches-1
Minor patches
Diffstat (limited to 'src/routes/event.ts')
-rw-r--r-- | src/routes/event.ts | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/routes/event.ts b/src/routes/event.ts index ad77052..3595e0a 100644 --- a/src/routes/event.ts +++ b/src/routes/event.ts @@ -642,4 +642,74 @@ router.post( }, ); +router.delete( + "/event/attendee/:eventID", + async (req: Request, res: Response) => { + const removalPassword = req.query.p; + if (!removalPassword) { + return res + .status(400) + .json({ error: "Please provide a removal password." }); + } + try { + const response = await Event.findOne({ + id: req.params.eventID, + "attendees.removalPassword": removalPassword, + }); + if (!response) { + return res.status(404).json({ + error: "No attendee found with that removal password.", + }); + } + const attendee = response?.attendees?.find( + (a) => a.removalPassword === removalPassword, + ); + if (!attendee) { + return res.status(404).json({ + error: "No attendee found with that removal password.", + }); + } + const attendeeEmail = attendee.email; + const removalResponse = await Event.updateOne( + { id: req.params.eventID }, + { $pull: { attendees: { removalPassword } } }, + ); + if (removalResponse.nModified === 0) { + return res.status(404).json({ + error: "No attendee found with that removal password.", + }); + } + addToLog( + "unattendEvent", + "success", + `Attendee removed self from event ${req.params.eventID}`, + ); + if (attendeeEmail && req.app.locals.sendEmails) { + await sendEmailFromTemplate( + attendeeEmail, + "You have been removed from an event", + "unattendEvent", + { + eventID: req.params.eventID, + siteName: res.locals.config?.general.site_name, + siteLogo: res.locals.config?.general.email_logo_url, + domain: res.locals.config?.general.domain, + }, + req, + ); + } + res.sendStatus(200); + } catch (e) { + addToLog( + "removeEventAttendee", + "error", + `Attempt to remove attendee from event ${req.params.eventID} failed with error: ${e}`, + ); + return res.status(500).json({ + error: "There has been an unexpected error. Please try again.", + }); + } + }, +); + export default router; |