Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attendee filter body route #92

Merged
merged 6 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/services/attendee/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,
PartialAttendeeValidator,
} 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(
AydanPirani marked this conversation as resolved.
Show resolved Hide resolved
"/filter",
RoleChecker([Role.Enum.ADMIN]),
AydanPirani marked this conversation as resolved.
Show resolved Hide resolved
async (req, res, next) => {
try {
const attendeeData = PartialAttendeeValidator.parse(req.body);
const attendees = await Database.ATTENDEE.find(attendeeData);
AydanPirani marked this conversation as resolved.
Show resolved Hide resolved

return res.status(StatusCodes.OK).json(attendees);
} catch (error) {
next(error);
}
}
);

export default attendeeRouter;
4 changes: 4 additions & 0 deletions src/services/attendee/attendee-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();