From f0954c984523aa5eb1f6898b1f753fd2b3bb3c24 Mon Sep 17 00:00:00 2001 From: jain18ayush <41806429+jain18ayush@users.noreply.github.com> Date: Sun, 16 Oct 2022 18:19:08 -0500 Subject: [PATCH 1/2] Update events.ts --- src/routes/events.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/routes/events.ts b/src/routes/events.ts index 64747d0..d900046 100644 --- a/src/routes/events.ts +++ b/src/routes/events.ts @@ -11,7 +11,18 @@ router.use((_req, _res, next) => { // define the home page route router.get('/', async (_req, res) => { - const events = await Event.find({}); + //const events = await Event.find({}); + + let isActive: any|undefined = _req.query.active; + + let events = await Event.find({}); + + if(isActive !== undefined) { + events = await Event.find({ + active: isActive, + }) + } + res.send(events.map(toMaskedEvent)); }); From 9b7531bae00d370647c4fcdad6aad1325e520f4c Mon Sep 17 00:00:00 2001 From: jain18ayush <41806429+jain18ayush@users.noreply.github.com> Date: Sun, 16 Oct 2022 18:36:54 -0500 Subject: [PATCH 2/2] Make endpoint query case insensitive --- src/routes/events.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/events.ts b/src/routes/events.ts index d900046..82327e9 100644 --- a/src/routes/events.ts +++ b/src/routes/events.ts @@ -11,16 +11,16 @@ router.use((_req, _res, next) => { // define the home page route router.get('/', async (_req, res) => { - //const events = await Event.find({}); - - let isActive: any|undefined = _req.query.active; - - let events = await Event.find({}); + let isActive: any|undefined = _req.query.active; + + let events; if(isActive !== undefined) { events = await Event.find({ - active: isActive, + active: (isActive.toLowerCase() === 'true'), }) + } else { + events = await Event.find({}); } res.send(events.map(toMaskedEvent));