From 6d7a61828d50e444576717831c44f92db5ba79b4 Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Sat, 6 Jul 2024 22:15:22 -0700 Subject: [PATCH 1/5] attendee filter body --- src/services/attendees/attendee-router.ts | 22 +++++++++++++++++++++- src/services/attendees/attendee-schema.ts | 10 +++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/services/attendees/attendee-router.ts b/src/services/attendees/attendee-router.ts index f342319..0440ff7 100644 --- a/src/services/attendees/attendee-router.ts +++ b/src/services/attendees/attendee-router.ts @@ -1,6 +1,10 @@ import { Router } from "express"; import { StatusCodes } from "http-status-codes"; -import { AttendeeValidator, EventIdValidator } from "./attendee-schema"; +import { + AttendeeValidator, + EventIdValidator, + PartialAttendeeFilter, +} from "./attendee-schema"; import { Database } from "../../database"; import RoleChecker from "../../middleware/role-checker"; import { Role } from "../auth/auth-models"; @@ -150,4 +154,20 @@ attendeeRouter.get( } ); +// Get attendees based on a partial filter in body +attendeeRouter.post( + "/filter", + RoleChecker([Role.Enum.ADMIN]), + async (req, res, next) => { + try { + const attendeeData = PartialAttendeeFilter.parse(req.body); + const attendees = await Database.ATTENDEES.find(attendeeData); + + return res.status(StatusCodes.OK).json(attendees); + } catch (error) { + next(error); + } + } +); + export default attendeeRouter; diff --git a/src/services/attendees/attendee-schema.ts b/src/services/attendees/attendee-schema.ts index efe3f43..fd36560 100644 --- a/src/services/attendees/attendee-schema.ts +++ b/src/services/attendees/attendee-schema.ts @@ -62,4 +62,12 @@ const EventIdValidator = z.object({ eventId: z.string().uuid(), }); -export { AttendeeSchema, AttendeeValidator, EventIdValidator }; +// Partial schema for attendee filter +const PartialAttendeeFilter = AttendeeValidator.partial(); + +export { + AttendeeSchema, + AttendeeValidator, + EventIdValidator, + PartialAttendeeFilter, +}; From cc7ccf03ea38f041336cef808ca94ae8fa08045a Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Sat, 6 Jul 2024 22:57:07 -0700 Subject: [PATCH 2/5] fix merge conf --- src/services/attendee/attendee-router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/attendee/attendee-router.ts b/src/services/attendee/attendee-router.ts index b8d532c..1a6716b 100644 --- a/src/services/attendee/attendee-router.ts +++ b/src/services/attendee/attendee-router.ts @@ -161,7 +161,7 @@ attendeeRouter.post( async (req, res, next) => { try { const attendeeData = PartialAttendeeFilter.parse(req.body); - const attendees = await Database.ATTENDEES.find(attendeeData); + const attendees = await Database.ATTENDEE.find(attendeeData); return res.status(StatusCodes.OK).json(attendees); } catch (error) { From 36c56925da393b923bea4354177cb533a3f0a884 Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Sat, 6 Jul 2024 23:02:06 -0700 Subject: [PATCH 3/5] fix merge conf --- src/services/attendee/attendee-router.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/attendee/attendee-router.ts b/src/services/attendee/attendee-router.ts index 1a6716b..512a372 100644 --- a/src/services/attendee/attendee-router.ts +++ b/src/services/attendee/attendee-router.ts @@ -3,7 +3,7 @@ import { StatusCodes } from "http-status-codes"; import { AttendeeValidator, EventIdValidator, - PartialAttendeeFilter, + PartialAttendeeValidator, } from "./attendee-schema"; import { Database } from "../../database"; import RoleChecker from "../../middleware/role-checker"; @@ -160,7 +160,7 @@ attendeeRouter.post( RoleChecker([Role.Enum.ADMIN]), async (req, res, next) => { try { - const attendeeData = PartialAttendeeFilter.parse(req.body); + const attendeeData = PartialAttendeeValidator.parse(req.body); const attendees = await Database.ATTENDEE.find(attendeeData); return res.status(StatusCodes.OK).json(attendees); From 98f87096b0c53669305287182e4a5a16cf4dafb5 Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Sat, 6 Jul 2024 23:03:57 -0700 Subject: [PATCH 4/5] fix merge conf --- src/services/attendee/attendee-schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/attendee/attendee-schema.ts b/src/services/attendee/attendee-schema.ts index 7d6d2fa..d85cc6e 100644 --- a/src/services/attendee/attendee-schema.ts +++ b/src/services/attendee/attendee-schema.ts @@ -75,4 +75,4 @@ export const EventIdValidator = z.object({ }); // Partial schema for attendee filter -export const PartialAttendeeFilter = AttendeeValidator.partial(); +export const PartialAttendeeValidator = AttendeeValidator.partial(); From 718a60942859920a625090d667f85fd396501e4d Mon Sep 17 00:00:00 2001 From: Jacob Chang Date: Sun, 7 Jul 2024 09:22:04 -0700 Subject: [PATCH 5/5] fix comments --- src/services/attendee/attendee-router.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/services/attendee/attendee-router.ts b/src/services/attendee/attendee-router.ts index 512a372..1fb2187 100644 --- a/src/services/attendee/attendee-router.ts +++ b/src/services/attendee/attendee-router.ts @@ -155,13 +155,16 @@ attendeeRouter.get( ); // Get attendees based on a partial filter in body -attendeeRouter.post( +attendeeRouter.get( "/filter", - RoleChecker([Role.Enum.ADMIN]), + RoleChecker([Role.Enum.STAFF, Role.Enum.CORPORATE]), async (req, res, next) => { try { const attendeeData = PartialAttendeeValidator.parse(req.body); - const attendees = await Database.ATTENDEE.find(attendeeData); + const attendees = await Database.ATTENDEE.find( + attendeeData, + "userId" + ); return res.status(StatusCodes.OK).json(attendees); } catch (error) {