diff --git a/src/services/attendee/attendee-router.ts b/src/services/attendee/attendee-router.ts index 4401cbb..bb3a140 100644 --- a/src/services/attendee/attendee-router.ts +++ b/src/services/attendee/attendee-router.ts @@ -1,10 +1,6 @@ import { Router } from "express"; import { StatusCodes } from "http-status-codes"; -import { - AttendeeValidator, - EventIdValidator, - AttendeeFilterValidator, -} from "./attendee-schema"; +import { AttendeeValidator, EventIdValidator } from "./attendee-schema"; import { Database } from "../../database"; import RoleChecker from "../../middleware/role-checker"; import { Role } from "../auth/auth-models"; @@ -178,23 +174,4 @@ 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 = AttendeeFilterValidator.parse(req.body); - const projection = Object.assign({}, ...attendeeData.projection); - const attendees = await Database.ATTENDEE.find( - attendeeData.filter, - projection - ); - 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 9e3088b..bd10f88 100644 --- a/src/services/attendee/attendee-schema.ts +++ b/src/services/attendee/attendee-schema.ts @@ -12,7 +12,6 @@ export const AttendeeValidator = z.object({ hasCheckedIn: z.boolean().default(false), points: z.number().min(0).default(0), foodWave: z.number().int().min(0).default(0), - hasResume: z.boolean(), hasPriority: z .object({ Mon: z.boolean().default(false), @@ -45,7 +44,6 @@ export const AttendeeSchema = new Schema({ hasCheckedIn: { type: Boolean, default: false }, points: { type: Number, default: 0 }, foodWave: { type: Number, default: 0 }, - hasResume: { type: Boolean, default: false }, hasPriority: { type: new Schema( { @@ -92,10 +90,3 @@ export const EventIdValidator = z.object({ // Partial schema for attendee filter export const PartialAttendeeValidator = AttendeeValidator.partial(); - -export const AttendeeFilterValidator = z.object({ - filter: PartialAttendeeValidator, - projection: z.array( - z.record(PartialAttendeeValidator.keyof(), z.number().min(1).max(1)) - ), -}); diff --git a/src/services/registration/registration-router.ts b/src/services/registration/registration-router.ts index bb83dfd..6f37e2f 100644 --- a/src/services/registration/registration-router.ts +++ b/src/services/registration/registration-router.ts @@ -1,6 +1,9 @@ import { Router } from "express"; import { StatusCodes } from "http-status-codes"; -import { RegistrationValidator } from "./registration-schema"; +import { + RegistrationFilterValidator, + RegistrationValidator, +} from "./registration-schema"; import { Database } from "../../database"; import RoleChecker from "../../middleware/role-checker"; import { Role } from "../auth/auth-models"; @@ -107,4 +110,23 @@ registrationRouter.get("/", RoleChecker([]), async (req, res, next) => { } }); +// Get attendees based on a partial filter in body +registrationRouter.get( + "/filter", + RoleChecker([Role.Enum.STAFF, Role.Enum.CORPORATE]), + async (req, res, next) => { + try { + const filterData = RegistrationFilterValidator.parse(req.body); + const projection = Object.assign({}, ...filterData.projection); + const attendees = await Database.REGISTRATION.find( + filterData.filter, + { ...projection, hasSubmitted: 1 } + ); + return res.status(StatusCodes.OK).json(attendees); + } catch (error) { + next(error); + } + } +); + export default registrationRouter; diff --git a/src/services/registration/registration-schema.ts b/src/services/registration/registration-schema.ts index 30f5a80..892b4b6 100644 --- a/src/services/registration/registration-schema.ts +++ b/src/services/registration/registration-schema.ts @@ -49,4 +49,18 @@ const RegistrationSchema = new mongoose.Schema({ hasSubmitted: { type: Boolean, default: false }, }); -export { RegistrationSchema, RegistrationValidator }; +// Partial schema for attendee filter +const PartialRegistrationValidator = RegistrationValidator.partial(); + +const RegistrationFilterValidator = z.object({ + filter: PartialRegistrationValidator, + projection: z.array( + z.record(PartialRegistrationValidator.keyof(), z.number().min(1).max(1)) + ), +}); + +export { + RegistrationSchema, + RegistrationValidator, + RegistrationFilterValidator, +};