From e70c9f352ccdd3b12d2fe3540be8c739285a596a Mon Sep 17 00:00:00 2001 From: Jason Zheng <48730262+jasozh@users.noreply.github.com> Date: Sun, 28 Apr 2024 19:32:25 -0400 Subject: [PATCH] Add option to include attendees in GET events (#256) --- backend/src/events/controllers.ts | 5 ++++- backend/src/events/views.ts | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/backend/src/events/controllers.ts b/backend/src/events/controllers.ts index 0b567cac..dfc8d261 100644 --- a/backend/src/events/controllers.ts +++ b/backend/src/events/controllers.ts @@ -81,6 +81,9 @@ const getEvents = async ( pagination: { after: string; limit: string; + }, + include: { + attendees: boolean; } ) => { /* SORTING */ @@ -116,7 +119,7 @@ const getEvents = async ( /* FILTERING */ let whereDict: { [key: string]: any } = {}; - let includeDict: { [key: string]: any } = {}; + let includeDict: { [key: string]: any } = include; // Handles GET /events?date=upcoming and GET /events?date=past // TODO: Investigate creating events that occur in a few minutes into the future diff --git a/backend/src/events/views.ts b/backend/src/events/views.ts index 81691793..c109d7eb 100644 --- a/backend/src/events/views.ts +++ b/backend/src/events/views.ts @@ -97,7 +97,13 @@ eventRouter.get("/", useAuth, async (req: Request, res: Response) => { limit: req.query.limit as string, }; - attempt(res, 200, () => eventController.getEvents(filter, sort, pagination)); + const include = { + attendees: req.query.include === "attendees" ? true : false, + }; + + attempt(res, 200, () => + eventController.getEvents(filter, sort, pagination, include) + ); }); eventRouter.get("/upcoming", useAuth, async (req: Request, res: Response) => {