fix stats breaking new player profiles

This commit is contained in:
yohlo
2025-10-08 09:03:29 -05:00
parent 49bbd1611c
commit 15bbca8b90
2 changed files with 26 additions and 8 deletions

View File

@@ -66,10 +66,28 @@ export function createPlayersService(pb: PocketBase) {
},
async getPlayerStats(playerId: string): Promise<PlayerStats> {
const result = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
`player_id = "${playerId}"`
);
return result;
try {
const result = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
`player_id = "${playerId}"`
);
return result;
} catch (error) {
return {
id: "",
player_id: playerId,
player_name: "",
matches: 0,
tournaments: 0,
wins: 0,
losses: 0,
total_cups_made: 0,
total_cups_against: 0,
win_percentage: 0,
avg_cups_per_match: 0,
margin_of_victory: 0,
margin_of_loss: 0,
};
}
},
async getAllPlayerStats(): Promise<PlayerStats[]> {