Validate permission to report results

This commit is contained in:
Kalle
2022-08-13 15:54:18 +03:00
parent cc1dee675c
commit 1a353c350b

View File

@@ -96,6 +96,7 @@ const reportWinnersParamsSchema = z.object({
});
export const action: ActionFunction = async ({ request, params }) => {
const user = await requireUser(request);
const parsedParams = reportWinnersParamsSchema.parse(params);
const parsedInput = await safeParseRequestFormData({
request,
@@ -108,6 +109,16 @@ export const action: ActionFunction = async ({ request, params }) => {
};
}
const event = notFoundIfFalsy(db.calendarEvents.findById(parsedParams.id));
validate(
canReportCalendarEventWinners({
user,
event,
startTimes: event.startTimes,
}),
401
);
db.calendarEvents.upsertReportedScores({
eventId: parsedParams.id,
participantCount: parsedInput.data.participantCount,