From df297d0c9972a95806acff7b385fa5eb712fbea9 Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 28 Oct 2024 13:35:14 +0000 Subject: [PATCH] maybe fix player data tracking idk --- .../backend/src/service/player.service.ts | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/projects/backend/src/service/player.service.ts b/projects/backend/src/service/player.service.ts index b333bb2..649bfc3 100644 --- a/projects/backend/src/service/player.service.ts +++ b/projects/backend/src/service/player.service.ts @@ -47,8 +47,8 @@ export class PlayerService { newPlayer.trackedSince = new Date(); await newPlayer.save(); - await this.seedPlayerHistory(newPlayer.id, playerToken); - await this.refreshAllPlayerScores(newPlayer.id); + await this.seedPlayerHistory(newPlayer, playerToken); + await this.refreshAllPlayerScores(newPlayer); // Notify in production if (isProduction()) { @@ -83,15 +83,10 @@ export class PlayerService { * Seeds the player's history using data from * the ScoreSaber API. * - * @param playerId the player id + * @param player the player to seed * @param playerToken the SoreSaber player token */ - public static async seedPlayerHistory(playerId: string, playerToken: ScoreSaberPlayerToken): Promise { - const player = await PlayerModel.findById(playerId); - if (player == null) { - throw new NotFoundError(`Player "${playerId}" not found`); - } - + public static async seedPlayerHistory(player: PlayerDocument, playerToken: ScoreSaberPlayerToken): Promise { // Loop through rankHistory in reverse, from current day backwards const playerRankHistory = playerToken.histories.split(",").map((value: string) => { return parseInt(value); @@ -255,14 +250,9 @@ export class PlayerService { /** * Refreshes all the players scores. * - * @param playerId the player's id + * @param player the player to refresh */ - public static async refreshAllPlayerScores(playerId: string) { - const player = await PlayerModel.findById(playerId); - if (player == null) { - throw new NotFoundError(`Player "${playerId}" not found`); - } - + public static async refreshAllPlayerScores(player: PlayerDocument) { await this.refreshPlayerScoreSaberScores(player); }