i think working bracket runner

This commit is contained in:
yohlo
2025-09-11 15:59:27 -05:00
parent 8dfff139e1
commit 3ffa6b03c7
10 changed files with 424 additions and 139 deletions

View File

@@ -174,5 +174,39 @@ export const endMatch = createServerFn()
away_cups,
ot_count
})
const matchWinner = home_cups > away_cups ? match.home : match.away;
const matchLoser = home_cups < away_cups ? match.home : match.away;
if (!matchWinner || !matchLoser) throw new Error("Something went wrong")
// winner -> where to send match winner to, loser same
const { winner, loser } = await pbAdmin.getChildMatches(matchId)
console.log('match winner:', matchWinner)
console.log('match loser:', matchLoser)
if (winner) {
await pbAdmin.updateMatch(winner.id, {
[winner.home_from_lid === match.lid ? "home" : "away"]: matchWinner,
status:
((winner.home_from_lid === match.lid) && winner.away)
|| ((winner.away_from_lid === match.lid) && winner.home)
? 'ready' : 'tbd'
})
}
if (loser) {
await pbAdmin.updateMatch(loser.id, {
[loser.home_from_lid === match.lid ? "home" : "away"]: matchLoser,
status:
((loser.home_from_lid === match.lid) && loser.away)
|| ((loser.away_from_lid === match.lid) && loser.home)
? 'ready' : 'tbd'
})
}
// TODO: send SSE
return match;
}
));