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;
}
));

View File

@@ -4,39 +4,6 @@ import { TournamentInfo } from "../tournaments/types";
export type MatchStatus = "tbd" | "ready" | "started" | "ended";
/**
* class TMatchSlot(BaseModel):
pass
class Seed(TMatchSlot):
seed: int
class TBD(TMatchSlot):
parent: "TMatchBase"
loser: bool
class TMatchBase(BaseModel):
lid: int # local id
round: int
order: Optional[int] = None
class TMatch(TMatchBase):
home: Seed | TBD
away: Seed | TBD
reset: bool = False
def __repr__(self):
return f'{self.order}'
class TBye(TMatchBase):
home: Seed | TBD
*/
export interface Match {
id: string;
order: number;