mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
31 lines
1001 B
TypeScript
31 lines
1001 B
TypeScript
import { type LoaderFunctionArgs, redirect } from "@remix-run/node";
|
|
import { getUser } from "~/features/auth/core/user.server";
|
|
import { tournamentFromDB } from "~/features/tournament-bracket/core/Tournament.server";
|
|
import { parseParams } from "~/utils/remix.server";
|
|
import { tournamentRegisterPage } from "~/utils/urls";
|
|
import { idObject } from "~/utils/zod";
|
|
import * as TournamentSubRepository from "../TournamentSubRepository.server";
|
|
|
|
export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
|
const user = await getUser(request);
|
|
const { id: tournamentId } = parseParams({
|
|
params,
|
|
schema: idObject,
|
|
});
|
|
|
|
const tournament = await tournamentFromDB({ tournamentId, user });
|
|
if (!tournament.subsFeatureEnabled) {
|
|
throw redirect(tournamentRegisterPage(tournamentId));
|
|
}
|
|
|
|
const subs = await TournamentSubRepository.findSubsVisibleToUser({
|
|
tournamentId,
|
|
userId: user?.id,
|
|
});
|
|
|
|
return {
|
|
subs,
|
|
hasOwnSubPost: subs.some((sub) => sub.userId === user?.id),
|
|
};
|
|
};
|