mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
34 lines
922 B
TypeScript
34 lines
922 B
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { requireUser } from "~/features/auth/core/user.server";
|
|
import * as CalendarRepository from "~/features/calendar/CalendarRepository.server";
|
|
import {
|
|
notFoundIfFalsy,
|
|
parseParams,
|
|
unauthorizedIfFalsy,
|
|
} from "~/utils/remix.server";
|
|
import { idObject } from "~/utils/zod";
|
|
import { canReportCalendarEventWinners } from "../calendar-utils";
|
|
|
|
export const loader = async (args: LoaderFunctionArgs) => {
|
|
const params = parseParams({
|
|
params: args.params,
|
|
schema: idObject,
|
|
});
|
|
const user = requireUser();
|
|
const event = notFoundIfFalsy(await CalendarRepository.findById(params.id));
|
|
|
|
unauthorizedIfFalsy(
|
|
canReportCalendarEventWinners({
|
|
user,
|
|
event,
|
|
startTimes: event.startTimes,
|
|
}),
|
|
);
|
|
|
|
return {
|
|
name: event.name,
|
|
participantCount: event.participantCount,
|
|
winners: await CalendarRepository.findResultsByEventId(params.id),
|
|
};
|
|
};
|