mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-21 18:04:39 -05:00
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { cors } from "remix-utils/cors";
|
|
import { z } from "zod/v4";
|
|
import { tournamentFromDB } from "~/features/tournament-bracket/core/Tournament.server";
|
|
import { notFoundIfFalsy, parseParams } from "~/utils/remix.server";
|
|
import { id } from "~/utils/zod";
|
|
import {
|
|
handleOptionsRequest,
|
|
requireBearerAuth,
|
|
} from "../api-public-utils.server";
|
|
import type { GetTournamentBracketStandingsResponse } from "../schema";
|
|
|
|
const paramsSchema = z.object({
|
|
id,
|
|
bidx: z.coerce.number().int(),
|
|
});
|
|
|
|
export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
|
await handleOptionsRequest(request);
|
|
requireBearerAuth(request);
|
|
|
|
const { id, bidx } = parseParams({ params, schema: paramsSchema });
|
|
|
|
const tournament = await tournamentFromDB({
|
|
user: undefined,
|
|
tournamentId: id,
|
|
});
|
|
|
|
const bracket = notFoundIfFalsy(tournament.bracketByIdx(bidx));
|
|
notFoundIfFalsy(!bracket.preview);
|
|
|
|
const result: GetTournamentBracketStandingsResponse = {
|
|
standings: bracket.standings.map((standing) => ({
|
|
tournamentTeamId: standing.team.id,
|
|
placement: standing.placement,
|
|
stats: standing.stats,
|
|
})),
|
|
};
|
|
|
|
return await cors(request, Response.json(result));
|
|
};
|