diff options
Diffstat (limited to 'src/routes')
-rw-r--r-- | src/routes/event.ts | 70 | ||||
-rw-r--r-- | src/routes/frontend.ts | 7 |
2 files changed, 73 insertions, 4 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; diff --git a/src/routes/frontend.ts b/src/routes/frontend.ts index 51c207a..58128a0 100644 --- a/src/routes/frontend.ts +++ b/src/routes/frontend.ts @@ -527,8 +527,7 @@ router.get( eventGroup: eventGroup._id, }).sort("start"); const string = exportICal(events, eventGroup.name); - res.set("Content-Type", "text/calendar"); - res.send(string); + res.set("Content-Type", "text/calendar").send(string); } } catch (err) { addToLog( @@ -550,7 +549,7 @@ router.get("/export/event/:eventID", async (req: Request, res: Response) => { if (event) { const string = exportICal([event], event.name); - res.send(string); + res.set("Content-Type", "text/calendar").send(string); } } catch (err) { addToLog( @@ -576,7 +575,7 @@ router.get( eventGroup: eventGroup._id, }).sort("start"); const string = exportICal(events, eventGroup.name); - res.send(string); + res.set("Content-Type", "text/calendar").send(string); } } catch (err) { addToLog( |