fix tiebreaker handling

This commit is contained in:
2026-03-07 04:47:56 +01:00
parent 31223e7bca
commit 0d94cbb4a0
4 changed files with 154 additions and 48 deletions

View File

@@ -6,6 +6,7 @@ import {
matchGame,
matchGameScore,
matchQueue,
mappoolSlot,
playerRating,
teamMember
} from '$lib/server/db/schema';
@@ -407,6 +408,24 @@ export async function pickMap(matchId: string, participantId: string, mappoolSlo
throw new Error('This map has already been played');
}
// ── Tiebreaker restrictions ──
const config = m.config as MatchConfig;
const winsNeeded = Math.ceil(config.bestOf / 2);
const allAtMatchPoint = participants.every((p) => p.score === winsNeeded - 1);
const slot = await db.query.mappoolSlot.findFirst({
where: eq(mappoolSlot.id, mappoolSlotId)
});
if (slot) {
if (slot.category === 'TB' && !allAtMatchPoint) {
throw new Error('Tiebreaker can only be picked at match point');
}
if (allAtMatchPoint && slot.category !== 'TB') {
throw new Error('Only tiebreaker maps can be picked at match point');
}
}
const [game] = await db
.insert(matchGame)
.values({