Skip to content

Commit

Permalink
Add list of teams to GetTournamentBracketResponse (api public) Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sendouc committed Dec 29, 2024
1 parent 35553a8 commit c2f1896
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/features/api-public/routes/tournament.$id.brackets.$bidx.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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"
Expand All @@ -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,
})),
);
}
4 changes: 4 additions & 0 deletions app/features/api-public/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c2f1896

Please sign in to comment.