mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-25 07:32:19 -05:00
Get round and bracket details from tournament-match endpoint Closes #2062
This commit is contained in:
parent
55397736df
commit
11974c9054
|
|
@ -3,6 +3,7 @@ import { jsonArrayFrom } from "kysely/helpers/sqlite";
|
|||
import { cors } from "remix-utils/cors";
|
||||
import { z } from "zod";
|
||||
import { db } from "~/db/sql";
|
||||
import { tournamentFromDBCached } from "~/features/tournament-bracket/core/Tournament.server";
|
||||
import { resolveMapList } from "~/features/tournament-bracket/core/mapList.server";
|
||||
import * as TournamentRepository from "~/features/tournament/TournamentRepository.server";
|
||||
import i18next from "~/modules/i18n/i18next.server";
|
||||
|
|
@ -138,6 +139,13 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
|||
});
|
||||
};
|
||||
|
||||
const { bracketName, roundNameWithoutMatchIdentifier } = (
|
||||
await tournamentFromDBCached({
|
||||
tournamentId: match.tournamentId,
|
||||
user: undefined,
|
||||
})
|
||||
).matchNameById(id);
|
||||
|
||||
const result: GetTournamentMatchResponse = {
|
||||
teamOne: match.opponentOne.id
|
||||
? {
|
||||
|
|
@ -153,6 +161,8 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
|
|||
: null,
|
||||
url: `https://sendou.ink/to/${match.tournamentId}/matches/${id}`,
|
||||
mapList: await mapList(),
|
||||
bracketName: bracketName ?? null,
|
||||
roundName: roundNameWithoutMatchIdentifier ?? null,
|
||||
};
|
||||
|
||||
return await cors(request, json(result));
|
||||
|
|
|
|||
|
|
@ -195,6 +195,18 @@ type TournamentCastChannel = {
|
|||
export interface GetTournamentMatchResponse {
|
||||
teamOne: TournamentMatchTeam | null;
|
||||
teamTwo: TournamentMatchTeam | null;
|
||||
/**
|
||||
* Name of the bracket this match belongs to.
|
||||
*
|
||||
* @example "Alpha Bracket"
|
||||
*/
|
||||
bracketName: string | null;
|
||||
/**
|
||||
* Name of the round this match belongs to.
|
||||
*
|
||||
* @example "Grand Finals"
|
||||
*/
|
||||
roundName: string | null;
|
||||
mapList: Array<MapListMap> | null;
|
||||
/**
|
||||
* @example "https://sendou.ink/to/9/matches/695"
|
||||
|
|
|
|||
|
|
@ -92,6 +92,15 @@ export async function tournamentFromDB(args: {
|
|||
return new Tournament({ ...data, simulateBrackets: false });
|
||||
}
|
||||
|
||||
export async function tournamentFromDBCached(args: {
|
||||
user: { id: number } | undefined;
|
||||
tournamentId: number;
|
||||
}) {
|
||||
const data = notFoundIfFalsy(await tournamentDataCached(args));
|
||||
|
||||
return new Tournament({ ...data, simulateBrackets: false });
|
||||
}
|
||||
|
||||
// caching promise ensures that if many requests are made for the same tournament
|
||||
// at the same time they reuse the same resolving promise
|
||||
const tournamentDataCache = new Map<
|
||||
|
|
|
|||
|
|
@ -1017,7 +1017,7 @@ export class Tournament {
|
|||
if (!roundName) return;
|
||||
|
||||
if (roundName.includes("Semis")) {
|
||||
return roundName.replace(/\d/g, "");
|
||||
return roundName.replace(/\d/g, "").trim();
|
||||
}
|
||||
|
||||
return roundName.split(".")[0];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user