Files
car-crushers-portal/functions/api/events-team/events/list.ts
Regalijan 5c17f87f89
All checks were successful
Test, Build, Deploy / Test, Build, and Deploy (push) Successful in 58s
Test, Build, Deploy / Create Sentry Release (push) Successful in 6s
Migrate the rest of the easy stuff
2026-04-11 04:32:09 -04:00

41 lines
1.1 KiB
TypeScript

import { jsonError, jsonResponse } from "../../../common.js";
export async function onRequestGet(context: RequestContext) {
const url = new URL(context.request.url);
const month = parseInt(url.searchParams.get("month") ?? "");
const year = parseInt(url.searchParams.get("year") ?? "");
if (isNaN(month) || isNaN(year))
return jsonError("Invalid month or year", 400);
const currentYear = new Date().getUTCFullYear();
const currentMonth = new Date().getUTCMonth() + 1;
if (currentYear < year || (currentYear === year && currentMonth < month))
return jsonError("Cannot get events for a time in the future", 400);
const eventRecords = await context.data.prisma.event.findMany({
select: {
answer: true,
approved: true,
created_by: true,
day: true,
details: true,
month: true,
pending: true,
performed_at: true,
type: true,
year: true,
},
where: {
month: month,
year: year,
},
orderBy: {
day: "asc",
},
});
return jsonResponse(JSON.stringify(eventRecords));
}