match list

This commit is contained in:
yohlo
2025-09-14 21:59:15 -05:00
parent d11e50d4ef
commit 8efc0a7a4b
9 changed files with 411 additions and 111 deletions

View File

@@ -5,7 +5,8 @@ import type {
PlayerUpdateInput,
PlayerStats,
} from "@/features/players/types";
import { transformPlayer, transformPlayerInfo } from "@/lib/pocketbase/util/transform-types";
import type { Match } from "@/features/matches/types";
import { transformPlayer, transformPlayerInfo, transformMatch } from "@/lib/pocketbase/util/transform-types";
import PocketBase from "pocketbase";
import { DataFetchOptions } from "./base";
@@ -77,5 +78,29 @@ export function createPlayersService(pb: PocketBase) {
});
return result;
},
async getPlayerMatches(playerId: string): Promise<Match[]> {
const player = await pb.collection("players").getOne(playerId, {
expand: "teams",
});
if (!player.expand?.teams || player.expand.teams.length === 0) {
return [];
}
const teamIds = Array.isArray(player.expand.teams)
? player.expand.teams.map((team: any) => team.id)
: [player.expand.teams.id];
const teamFilter = teamIds.map(teamId => `home = "${teamId}" || away = "${teamId}"`).join(" || ");
const result = await pb.collection("matches").getFullList({
filter: `(${teamFilter}) && (status = "ended" || status = "started")`,
sort: "-created",
expand: "tournament,home,away",
});
return result.map(transformMatch);
},
};
}