match h2h
This commit is contained in:
@@ -71,5 +71,58 @@ export function createMatchesService(pb: PocketBase) {
|
||||
matches.map((match) => pb.collection("matches").delete(match.id))
|
||||
);
|
||||
},
|
||||
|
||||
async getMatchesBetweenPlayers(player1Id: string, player2Id: string): Promise<Match[]> {
|
||||
logger.info("PocketBase | Getting matches between players", { player1Id, player2Id });
|
||||
|
||||
const player1Teams = await pb.collection("teams").getFullList({
|
||||
filter: `players ~ "${player1Id}"`,
|
||||
fields: "id",
|
||||
});
|
||||
|
||||
const player2Teams = await pb.collection("teams").getFullList({
|
||||
filter: `players ~ "${player2Id}"`,
|
||||
fields: "id",
|
||||
});
|
||||
|
||||
const player1TeamIds = player1Teams.map(t => t.id);
|
||||
const player2TeamIds = player2Teams.map(t => t.id);
|
||||
|
||||
if (player1TeamIds.length === 0 || player2TeamIds.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const filterConditions: string[] = [];
|
||||
player1TeamIds.forEach(team1Id => {
|
||||
player2TeamIds.forEach(team2Id => {
|
||||
filterConditions.push(`(home="${team1Id}" && away="${team2Id}")`);
|
||||
filterConditions.push(`(home="${team2Id}" && away="${team1Id}")`);
|
||||
});
|
||||
});
|
||||
|
||||
const filter = filterConditions.join(" || ");
|
||||
|
||||
const results = await pb.collection("matches").getFullList({
|
||||
filter,
|
||||
expand: "tournament, home, away, home.players, away.players",
|
||||
sort: "-created",
|
||||
});
|
||||
|
||||
return results.map(match => transformMatch(match));
|
||||
},
|
||||
|
||||
async getMatchesBetweenTeams(team1Id: string, team2Id: string): Promise<Match[]> {
|
||||
logger.info("PocketBase | Getting matches between teams", { team1Id, team2Id });
|
||||
|
||||
const filter = `(home="${team1Id}" && away="${team2Id}") || (home="${team2Id}" && away="${team1Id}")`;
|
||||
|
||||
const results = await pb.collection("matches").getFullList({
|
||||
filter,
|
||||
expand: "tournament, home, away, home.players, away.players",
|
||||
sort: "-created",
|
||||
});
|
||||
|
||||
return results.map(match => transformMatch(match));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user