Files
car-crushers-portal/functions/api/events-team/events/[id]/_middleware.ts
Regalijan cfc57c838e
All checks were successful
Test, Build, Deploy / Test, Build, and Deploy (push) Successful in 55s
Test, Build, Deploy / Create Sentry Release (push) Successful in 6s
More events team nonsense
2026-04-11 03:30:46 -04:00

23 lines
699 B
TypeScript

import { jsonError } from "../../../../common.js";
export async function onRequest(context: RequestContext) {
const pathSegments = new URL(context.request.url).pathname.split("/");
// Skip checks for the by-id endpoint
if (pathSegments.length <= 5) return await context.next();
const eventInfo = await context.data.prisma.event.findUnique({
where: {
id: context.params.id as string,
},
});
if (!eventInfo) return jsonError("This event does not exist.", 404);
if (![1 << 4, 1 << 12].find((p) => context.data.current_user.permissions & p))
return jsonError("You cannot manage this event.", 403);
context.data.event = eventInfo;
return await context.next();
}