fix stats breaking new player profiles
This commit is contained in:
@@ -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[]> {
|
||||
|
||||
Reference in New Issue
Block a user