sendou.ink/app/features/tournament-bracket/loaders/to.$id.matches.$mid.server.ts
Kalle 12590ba0df
Some checks failed
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled
Drop some unused columns, make TournamentRounds.maps always to be defined
2025-07-25 21:48:07 +03:00

49 lines
1.5 KiB
TypeScript

import type { LoaderFunctionArgs } from "@remix-run/node";
import * as TournamentRepository from "~/features/tournament/TournamentRepository.server";
import { notFoundIfFalsy, parseParams } from "~/utils/remix.server";
import { resolveMapList } from "../core/mapList.server";
import { findMatchById } from "../queries/findMatchById.server";
import { findResultsByMatchId } from "../queries/findResultsByMatchId.server";
import { matchPageParamsSchema } from "../tournament-bracket-schemas.server";
export type TournamentMatchLoaderData = typeof loader;
export const loader = async ({ params }: LoaderFunctionArgs) => {
const { mid: matchId, id: tournamentId } = parseParams({
params,
schema: matchPageParamsSchema,
});
const match = notFoundIfFalsy(findMatchById(matchId));
const isBye = !match.opponentOne || !match.opponentTwo;
if (isBye) {
throw new Response(null, { status: 404 });
}
const pickBanEvents = match.roundMaps?.pickBan
? await TournamentRepository.pickBanEventsByMatchId(match.id)
: [];
const mapList =
match.opponentOne?.id && match.opponentTwo?.id
? resolveMapList({
tournamentId,
matchId,
teams: [match.opponentOne.id, match.opponentTwo.id],
mapPickingStyle: match.mapPickingStyle,
maps: match.roundMaps,
pickBanEvents,
})
: null;
return {
match,
results: findResultsByMatchId(matchId),
mapList,
matchIsOver:
match.opponentOne?.result === "win" ||
match.opponentTwo?.result === "win",
};
};