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

@@ -8,7 +8,6 @@ import type {
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";
export function createPlayersService(pb: PocketBase) {
return {
@@ -65,9 +64,15 @@ export function createPlayersService(pb: PocketBase) {
return result.map(transformPlayer);
},
async getPlayerStats(playerId: string): Promise<PlayerStats> {
async getPlayerStats(playerId: string, viewType: 'all' | 'mainline' | 'regional' = 'all'): Promise<PlayerStats> {
try {
const result = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
const collectionMap = {
all: 'player_stats',
mainline: 'player_mainline_stats',
regional: 'player_regional_stats',
};
const result = await pb.collection(collectionMap[viewType]).getFirstListItem<PlayerStats>(
`player_id = "${playerId}"`
);
return result;
@@ -90,8 +95,14 @@ export function createPlayersService(pb: PocketBase) {
}
},
async getAllPlayerStats(): Promise<PlayerStats[]> {
const result = await pb.collection("player_stats").getFullList<PlayerStats>({
async getAllPlayerStats(viewType: 'all' | 'mainline' | 'regional' = 'all'): Promise<PlayerStats[]> {
const collectionMap = {
all: 'player_stats',
mainline: 'player_mainline_stats',
regional: 'player_regional_stats',
};
const result = await pb.collection(collectionMap[viewType]).getFullList<PlayerStats>({
sort: "-win_percentage,-total_cups_made",
});
return result;