i think working bracket runner
This commit is contained in:
@@ -13,6 +13,28 @@ export function createMatchesService(pb: PocketBase) {
|
||||
return transformMatch(result);
|
||||
},
|
||||
|
||||
// match Ids where the current lid is home_from_lid or away_from_lid
|
||||
async getChildMatches(matchId: string): Promise<{ winner: Match | undefined, loser: Match | undefined }> {
|
||||
logger.info("PocketBase | Getting child matches", matchId);
|
||||
const match = await this.getMatch(matchId);
|
||||
if (!match) throw new Error("Match not found")
|
||||
|
||||
const result = await pb.collection("matches").getFullList({
|
||||
filter: `tournament="${match.tournament.id}" && (home_from_lid = ${match.lid} || away_from_lid = ${match.lid})`,
|
||||
expand: "tournament, home, away",
|
||||
});
|
||||
|
||||
const winnerMatch = result.find(m => (m.home_from_lid === match.lid && !m.home_from_loser) || (m.away_from_lid === match.lid && !m.away_from_loser));
|
||||
const loserMatch = result.find(m => (m.home_from_lid === match.lid && m.home_from_loser) || (m.away_from_lid === match.lid && m.away_from_loser));
|
||||
|
||||
console.log(winnerMatch, loserMatch)
|
||||
|
||||
return {
|
||||
winner: winnerMatch ? transformMatch(winnerMatch) : undefined,
|
||||
loser: loserMatch ? transformMatch(loserMatch) : undefined
|
||||
}
|
||||
},
|
||||
|
||||
async createMatch(data: MatchInput): Promise<Match> {
|
||||
logger.info("PocketBase | Creating match", data);
|
||||
const result = await pb.collection("matches").create<Match>(data);
|
||||
|
||||
Reference in New Issue
Block a user