mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { type LoaderFunctionArgs, redirect } from "react-router";
|
|
import { requireUser } from "~/features/auth/core/user.server";
|
|
import { tournamentFromDB } from "~/features/tournament-bracket/core/Tournament.server";
|
|
import * as UserRepository from "~/features/user-page/UserRepository.server";
|
|
import { parseParams } from "~/utils/remix.server";
|
|
import { tournamentSubsPage } from "~/utils/urls";
|
|
import { idObject } from "~/utils/zod";
|
|
import * as TournamentSubRepository from "../TournamentSubRepository.server";
|
|
|
|
export const loader = async ({ params }: LoaderFunctionArgs) => {
|
|
const user = requireUser();
|
|
const { id: tournamentId } = parseParams({
|
|
params,
|
|
schema: idObject,
|
|
});
|
|
const tournament = await tournamentFromDB({ tournamentId, user });
|
|
|
|
if (!tournament.canAddNewSubPost) {
|
|
throw redirect(tournamentSubsPage(tournamentId));
|
|
}
|
|
|
|
return {
|
|
sub: await TournamentSubRepository.findUserSubPost({
|
|
tournamentId,
|
|
userId: user.id,
|
|
}),
|
|
userDefaults: await UserRepository.findSubDefaultsByUserId(user.id),
|
|
};
|
|
};
|