From c2f1896b481a55120c4764a21dd249118f66d084 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 29 Dec 2024 12:38:59 +0200 Subject: [PATCH] Add list of teams to GetTournamentBracketResponse (api public) Closes #1999 --- .../routes/tournament.$id.brackets.$bidx.ts | 19 +++++++++++++++++++ app/features/api-public/schema.ts | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/app/features/api-public/routes/tournament.$id.brackets.$bidx.ts b/app/features/api-public/routes/tournament.$id.brackets.$bidx.ts index 7ee6bbbd9c..345bcbae47 100644 --- a/app/features/api-public/routes/tournament.$id.brackets.$bidx.ts +++ b/app/features/api-public/routes/tournament.$id.brackets.$bidx.ts @@ -1,6 +1,7 @@ import { type LoaderFunctionArgs, json } from "@remix-run/node"; import { cors } from "remix-utils/cors"; import { z } from "zod"; +import type { Bracket } from "~/features/tournament-bracket/core/Bracket"; import { tournamentFromDB } from "~/features/tournament-bracket/core/Tournament.server"; import { notFoundIfFalsy, parseParams } from "~/utils/remix.server"; import { id } from "~/utils/zod"; @@ -30,6 +31,7 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => { const result: GetTournamentBracketResponse = { data: bracket.data, + teams: teams(bracket), meta: { teamsPerGroup: bracket.type === "round_robin" @@ -51,3 +53,20 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => { return await cors(request, json(result)); }; + +function teams(bracket: Bracket) { + const checkedIn = bracket.seeding ?? bracket.participantTournamentTeamIds; + const pending = bracket.teamsPendingCheckIn ?? []; + + return checkedIn + .map((teamId) => ({ + id: teamId, + checkedIn: true, + })) + .concat( + pending.map((teamId) => ({ + id: teamId, + checkedIn: false, + })), + ); +} diff --git a/app/features/api-public/schema.ts b/app/features/api-public/schema.ts index 28e4a35e88..0e0cf802db 100644 --- a/app/features/api-public/schema.ts +++ b/app/features/api-public/schema.ts @@ -171,6 +171,10 @@ export interface GetTournamentMatchResponse { export interface GetTournamentBracketResponse { data: TournamentBracketData; + teams: Array<{ + id: number; + checkedIn: boolean; + }>; meta: { /** How many teams per group? (round robin only) */ teamsPerGroup?: number;