From 8011ed7b5aecc552fd235abdef643ea506cbd438 Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 29 Oct 2024 18:44:21 +0000 Subject: [PATCH] add additional data in top scores response --- projects/backend/src/service/score.service.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/projects/backend/src/service/score.service.ts b/projects/backend/src/service/score.service.ts index 0235ebc..5f85de0 100644 --- a/projects/backend/src/service/score.service.ts +++ b/projects/backend/src/service/score.service.ts @@ -340,13 +340,15 @@ export class ScoreService { const scores: PlayerScore[] = []; for (const { score: scoreData } of foundScores) { const score = new ScoreSaberScoreModel(scoreData).toObject() as ScoreSaberScore; - const leaderboard = await LeaderboardService.getLeaderboard( + const leaderboardResponse = await LeaderboardService.getLeaderboard( "scoresaber", score.leaderboardId + "" ); - if (!leaderboard) { + if (!leaderboardResponse) { continue; } + const { leaderboard, beatsaver } = leaderboardResponse; + try { const player = await PlayerService.getPlayer(score.playerId); if (player !== undefined) { @@ -361,10 +363,20 @@ export class ScoreService { }; } + const additionalData = await ScoreService.getAdditionalScoreData( + score.playerId, + leaderboard.songHash, + `${leaderboard.difficulty.difficulty}-${leaderboard.difficulty.characteristic}`, + score.score + ); + if (additionalData) { + score.additionalData = additionalData; + } + scores.push({ score: score, - leaderboard: leaderboard.leaderboard, - beatSaver: leaderboard.beatsaver, + leaderboard: leaderboard, + beatSaver: beatsaver, }); } console.log(`Got ${scores.length} scores in ${Date.now() - before}ms (timeframe: ${timeframe}, limit: ${amount})`);