mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-26 09:20:24 -05:00
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
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 { assertUnreachable } from "~/utils/types";
|
|
import { tournamentRegisterPage } from "~/utils/urls";
|
|
import { idObject } from "~/utils/zod";
|
|
import { findSubsByTournamentId } from "../queries/findSubsByTournamentId.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 = findSubsByTournamentId({
|
|
tournamentId,
|
|
userId: user?.id,
|
|
// biome-ignore lint/suspicious/useIterableCallbackReturn: Biome 2.3.1 upgrade
|
|
}).filter((sub) => {
|
|
if (sub.visibility === "ALL") return true;
|
|
|
|
const userPlusTier = user?.plusTier ?? 4;
|
|
|
|
switch (sub.visibility) {
|
|
case "+1": {
|
|
return userPlusTier === 1;
|
|
}
|
|
case "+2": {
|
|
return userPlusTier <= 2;
|
|
}
|
|
case "+3": {
|
|
return userPlusTier <= 3;
|
|
}
|
|
default: {
|
|
assertUnreachable(sub.visibility);
|
|
}
|
|
}
|
|
});
|
|
|
|
return {
|
|
subs,
|
|
hasOwnSubPost: subs.some((sub) => sub.userId === user?.id),
|
|
};
|
|
};
|