diff --git a/src/services/attendee/attendee-router.ts b/src/services/attendee/attendee-router.ts index 1d1ee17..1fb2187 100644 --- a/src/services/attendee/attendee-router.ts +++ b/src/services/attendee/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, + PartialAttendeeValidator, +} from "./attendee-schema"; import { Database } from "../../database"; import RoleChecker from "../../middleware/role-checker"; import { Role } from "../auth/auth-models"; @@ -150,4 +154,23 @@ attendeeRouter.get( } ); +// Get attendees based on a partial filter in body +attendeeRouter.get( + "/filter", + 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, + "userId" + ); + + return res.status(StatusCodes.OK).json(attendees); + } catch (error) { + next(error); + } + } +); + export default attendeeRouter; diff --git a/src/services/attendee/attendee-schema.ts b/src/services/attendee/attendee-schema.ts index a9324d6..d85cc6e 100644 --- a/src/services/attendee/attendee-schema.ts +++ b/src/services/attendee/attendee-schema.ts @@ -69,6 +69,10 @@ export const AttendeeAttendanceValidator = z.object({ userId: z.string(), eventsAttended: z.array(z.string()), }); + export const EventIdValidator = z.object({ eventId: z.string().uuid(), }); + +// Partial schema for attendee filter +export const PartialAttendeeValidator = AttendeeValidator.partial();