Skip to content

Commit

Permalink
attendee filter body
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobc2700 committed Jul 7, 2024
1 parent 25b50bd commit 6d7a618
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/services/attendees/attendee-router.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
10 changes: 9 additions & 1 deletion src/services/attendees/attendee-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

0 comments on commit 6d7a618

Please sign in to comment.