This commit is contained in:
yohlo
2025-10-18 23:09:57 -05:00
parent e58ed86d3b
commit dce31905fc

View File

@@ -377,9 +377,31 @@ export function createBadgesService(pb: PocketBase) {
for (const tournament of tournaments) { for (const tournament of tournaments) {
if (!tournamentIds.has(tournament.id)) continue; if (!tournamentIds.has(tournament.id)) continue;
if (tournament.winner_id === playerId) { const tournamentMatches = await pb.collection("matches").getFullList({
consecutiveWins++; filter: `tournament = "${tournament.id}" && status = "ended"`,
maxConsecutiveWins = Math.max(maxConsecutiveWins, consecutiveWins); expand: 'home,away,home.players,away.players',
});
const winnersMatches = tournamentMatches.filter(m => !m.is_losers_bracket);
const finalsMatch = winnersMatches.reduce((highest: any, current: any) =>
(!highest || current.lid > highest.lid) ? current : highest, null);
if (finalsMatch && finalsMatch.status === 'ended') {
const finalsWinnerId = (finalsMatch.home_cups > finalsMatch.away_cups) ? finalsMatch.home : finalsMatch.away;
const winningTeam = finalsMatch.expand?.[finalsWinnerId === finalsMatch.home ? 'home' : 'away'];
const winningPlayers = winningTeam?.expand?.players || winningTeam?.players || [];
const playerWon = winningPlayers.some((p: any) =>
(typeof p === 'string' ? p : p.id) === playerId
);
if (playerWon) {
consecutiveWins++;
maxConsecutiveWins = Math.max(maxConsecutiveWins, consecutiveWins);
} else {
consecutiveWins = 0;
}
} else { } else {
consecutiveWins = 0; consecutiveWins = 0;
} }