Skip to content

Commit

Permalink
Moved route
Browse files Browse the repository at this point in the history
  • Loading branch information
Aydan Pirani committed Jul 17, 2024
1 parent fbe965c commit b804159
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
25 changes: 1 addition & 24 deletions src/services/attendee/attendee-router.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
7 changes: 0 additions & 7 deletions src/services/attendee/attendee-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,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))
),
});
24 changes: 23 additions & 1 deletion src/services/registration/registration-router.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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.ATTENDEE.find(
filterData.filter,
projection
);
return res.status(StatusCodes.OK).json(attendees);
} catch (error) {
next(error);
}
}
);

export default registrationRouter;
16 changes: 15 additions & 1 deletion src/services/registration/registration-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

0 comments on commit b804159

Please sign in to comment.