From ad568ddf5db81df7bb60e6ff3afbe069bff1990d Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 28 Oct 2024 14:00:12 +0000 Subject: [PATCH] fix player data tracking --- projects/backend/src/index.ts | 46 +++++++++---------- projects/backend/src/service/score.service.ts | 7 ++- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/projects/backend/src/index.ts b/projects/backend/src/index.ts index 66e9659..e3644ca 100644 --- a/projects/backend/src/index.ts +++ b/projects/backend/src/index.ts @@ -61,30 +61,28 @@ connectBeatLeaderWebsocket({ }); export const app = new Elysia(); -if (isProduction()) { - app.use( - cron({ - name: "player-statistics-tracker-cron", - pattern: "1 0 * * *", // Every day at 00:01 - timezone: "Europe/London", // UTC time - protect: true, - run: async () => { - await PlayerService.updatePlayerStatistics(); - }, - }) - ); - app.use( - cron({ - name: "player-scores-tracker-cron", - pattern: "0 4 * * *", // Every day at 04:00 - timezone: "Europe/London", // UTC time - protect: true, - run: async () => { - await PlayerService.refreshPlayerScores(); - }, - }) - ); -} +app.use( + cron({ + name: "player-statistics-tracker-cron", + pattern: "0 1 * * * *", // Every day at 00:01 + timezone: "Europe/London", // UTC time + protect: true, + run: async () => { + await PlayerService.updatePlayerStatistics(); + }, + }) +); +app.use( + cron({ + name: "player-scores-tracker-cron", + pattern: "0 4 * * *", // Every day at 04:00 + timezone: "Europe/London", // UTC time + protect: true, + run: async () => { + await PlayerService.refreshPlayerScores(); + }, + }) +); /** * Custom error handler diff --git a/projects/backend/src/service/score.service.ts b/projects/backend/src/service/score.service.ts index 16cbadd..0590441 100644 --- a/projects/backend/src/service/score.service.ts +++ b/projects/backend/src/service/score.service.ts @@ -174,7 +174,12 @@ export class ScoreService { leaderboardToken: ScoreSaberLeaderboardToken, playerId?: string ) { - playerId = scoreToken.leaderboardPlayerInfo && (playerId || scoreToken.leaderboardPlayerInfo.id); + playerId = (scoreToken.leaderboardPlayerInfo && scoreToken.leaderboardPlayerInfo.id) || playerId; + if (!playerId) { + console.error(`Player ID is undefined, unable to track score: ${scoreToken.id}`); + return; + } + const playerName = (scoreToken.leaderboardPlayerInfo && scoreToken.leaderboardPlayerInfo.name) || "Unknown"; const leaderboard = getScoreSaberLeaderboardFromToken(leaderboardToken);