regionals

This commit is contained in:
yohlo
2025-10-16 09:12:11 -05:00
parent 612f1f28bf
commit 470b4ef99c
28 changed files with 962 additions and 97 deletions

View File

@@ -32,7 +32,7 @@ export function createMatchesService(pb: PocketBase) {
},
async createMatch(data: MatchInput): Promise<Match> {
logger.info("PocketBase | Creating match", data);
// logger.info("PocketBase | Creating match", data);
const result = await pb.collection("matches").create<Match>(data);
return result;
},
@@ -92,23 +92,40 @@ export function createMatchesService(pb: PocketBase) {
return [];
}
const filterConditions: string[] = [];
player1TeamIds.forEach(team1Id => {
player2TeamIds.forEach(team2Id => {
filterConditions.push(`(home="${team1Id}" && away="${team2Id}")`);
filterConditions.push(`(home="${team2Id}" && away="${team1Id}")`);
const allTeamIds = [...new Set([...player1TeamIds, ...player2TeamIds])];
const batchSize = 10;
const allMatches: any[] = [];
for (let i = 0; i < allTeamIds.length; i += batchSize) {
const batch = allTeamIds.slice(i, i + batchSize);
const teamFilters = batch.map(id => `home="${id}" || away="${id}"`).join(' || ');
const results = await pb.collection("matches").getFullList({
filter: teamFilters,
expand: "tournament, home, away, home.players, away.players",
sort: "-created",
});
});
const filter = filterConditions.join(" || ");
allMatches.push(...results);
}
const results = await pb.collection("matches").getFullList({
filter,
expand: "tournament, home, away, home.players, away.players",
sort: "-created",
});
const uniqueMatches = Array.from(
new Map(allMatches.map(m => [m.id, m])).values()
);
return results.map(match => transformMatch(match));
return uniqueMatches
.filter(match => {
const homeTeamId = typeof match.home === 'string' ? match.home : match.home?.id;
const awayTeamId = typeof match.away === 'string' ? match.away : match.away?.id;
const player1InHome = player1TeamIds.includes(homeTeamId);
const player1InAway = player1TeamIds.includes(awayTeamId);
const player2InHome = player2TeamIds.includes(homeTeamId);
const player2InAway = player2TeamIds.includes(awayTeamId);
return (player1InHome && player2InAway) || (player1InAway && player2InHome);
})
.map(match => transformMatch(match));
},
async getMatchesBetweenTeams(team1Id: string, team2Id: string): Promise<Match[]> {