Tournaments league mode (#3411)

This commit is contained in:
Kalle
2026-09-24 17:52:01 +03:00
committed by GitHub
parent 2353a064ad
commit 263dd557fb
165 changed files with 6164 additions and 271 deletions

View File

@@ -1013,6 +1013,53 @@ export function buildCases(fx: Fixtures): {
(tournamentTeamId) =>
TournamentMatchRepository.findByTournamentTeamId(tournamentTeamId),
);
add(
"TournamentMatchRepository.findScheduleProposalsByMatchId",
fx.scheduleProposal?.matchId ?? fx.heavyTournamentMatchId,
(matchId) =>
TournamentMatchRepository.findScheduleProposalsByMatchId(matchId),
);
add(
"TournamentMatchRepository.findLastResultAtsByTournamentId",
fx.heaviestBracketTournamentId,
(tournamentId) =>
TournamentMatchRepository.findLastResultAtsByTournamentId(tournamentId),
);
add(
"TournamentMatchRepository.findScheduledByUserIds",
both(fx.manyUserIds, fx.availabilityWindow),
([userIds, window]) =>
TournamentMatchRepository.findScheduledByUserIds({
userIds,
startsAt: window.startsAt,
endsAt: window.endsAt,
}),
);
add(
"TournamentMatchRepository.findScheduledByUserId",
both(fx.heavyUser, fx.availabilityWindow),
([user, window]) =>
TournamentMatchRepository.findScheduledByUserId({
userId: user.id,
startsAt: window.startsAt,
endsAt: window.endsAt,
}),
);
add(
"TournamentMatchRepository.findScheduledBetween",
fx.availabilityWindow,
(window) =>
TournamentMatchRepository.findScheduledBetween({
startsAt: window.startsAt,
endsAt: window.endsAt,
}),
);
add(
"TournamentMatchRepository.findScheduleProposalById",
fx.scheduleProposal,
(proposal) =>
TournamentMatchRepository.findScheduleProposalById(proposal.id),
);
add("TournamentOrganizationRepository.findBySlug", fx.heavyOrg, (org) =>
TournamentOrganizationRepository.findBySlug(org.slug),
@@ -1268,6 +1315,12 @@ export function buildCases(fx: Fixtures): {
addStatic("TournamentRepository.findRunningTournamentIds", () =>
TournamentRepository.findRunningTournamentIds(),
);
add(
"TournamentRepository.findDivisionTiersByTournamentId",
fx.heavyTournamentId,
(tournamentId) =>
TournamentRepository.findDivisionTiersByTournamentId(tournamentId),
);
add(
"TournamentTeamRepository.findAllByChatRoomIds",

View File

@@ -38,6 +38,8 @@ export interface Fixtures {
heavyResultsTournamentId: number | null;
heavyTournamentMatchId: number | null;
tournamentMatchGameResultId: number | null;
/** Newest proposal of the match with the most schedule proposals. */
scheduleProposal: { id: number; matchId: number } | null;
heavyTournamentTeamId: number | null;
tournamentTeamPair: [number, number] | null;
tournamentTeamInviteCode: string | null;
@@ -164,6 +166,7 @@ export async function resolveFixtures(): Promise<Fixtures> {
heavyResultsTournamentId: await resolveHeavyResultsTournamentId(),
heavyTournamentMatchId: await resolveHeavyTournamentMatchId(),
tournamentMatchGameResultId: await resolveTournamentMatchGameResultId(),
scheduleProposal: await resolveScheduleProposal(),
heavyTournamentTeamId:
await resolveHeavyTournamentTeamId(heavyTournamentId),
tournamentTeamPair: await resolveTournamentTeamPair(heavyTournamentId),
@@ -496,6 +499,23 @@ async function resolveTournamentMatchGameResultId() {
return row?.id ?? null;
}
async function resolveScheduleProposal() {
const row = await db
.selectFrom("TournamentMatchScheduleProposal")
.select(({ fn }) => [
"matchId",
fn.max("id").as("id"),
fn.countAll<number>().as("count"),
])
.groupBy("matchId")
.orderBy("count", "desc")
.limit(1)
.executeTakeFirst();
if (!row) return null;
return { id: row.id, matchId: row.matchId };
}
async function resolveHeavyTournamentTeamId(heavyTournamentId: number | null) {
if (heavyTournamentId === null) return null;