match list
This commit is contained in:
@@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user