Skip to content

Commit

Permalink
any linter fix + rename vars
Browse files Browse the repository at this point in the history
  • Loading branch information
riyap committed Aug 17, 2024
1 parent a0ab92d commit 9993b9b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
36 changes: 18 additions & 18 deletions src/services/registration/registration-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any> = { 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) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/registration/registration-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9993b9b

Please sign in to comment.