diff --git a/src/services/registration/registration-router.ts b/src/services/registration/registration-router.ts index f5602ed..f8e79bb 100644 --- a/src/services/registration/registration-router.ts +++ b/src/services/registration/registration-router.ts @@ -115,30 +115,30 @@ registrationRouter.post( RoleChecker([Role.Enum.STAFF, Role.Enum.CORPORATE], true), async (req, res, next) => { try { - const filterData = RegistrationFilterValidator.parse(req.body); + const { graduations, majors, jobInterests } = + RegistrationFilterValidator.parse(req.body); - // Build the query object with optional properties - const query: Record = { hasSubmitted: true }; - - if (filterData.graduations) { - query.graduation = { $in: filterData.graduations }; - } - - if (filterData.majors) { - query.major = { $in: filterData.majors }; - } - - if (filterData.jobs) { - query.jobInterest = { $elemMatch: { $in: filterData.jobs } }; - } - - const registrants = await Database.REGISTRATION.find(query, { + const query = { + hasSubmitted: true, + ...(graduations && { graduation: { $in: graduations } }), + ...(majors && { major: { $in: majors } }), + ...(jobInterests && { + jobInterest: { $elemMatch: { $in: jobInterests } }, + }), + }; + + const projection = { userId: 1, name: 1, major: 1, graduation: 1, jobInterest: 1, - }); + }; + + const registrants = await Database.REGISTRATION.find( + query, + projection + ); return res.status(StatusCodes.OK).json({ registrants }); } catch (error) { diff --git a/src/services/registration/registration-schema.ts b/src/services/registration/registration-schema.ts index 2c22504..c0d69e6 100644 --- a/src/services/registration/registration-schema.ts +++ b/src/services/registration/registration-schema.ts @@ -52,7 +52,7 @@ const RegistrationSchema = new mongoose.Schema({ const RegistrationFilterValidator = z.object({ graduations: z.array(z.string()).optional(), majors: z.array(z.string()).optional(), - jobs: z.array(z.string()).optional(), + jobInterests: z.array(z.string()).optional(), }); export {