diff --git a/src/score/score.controller.ts b/src/score/score.controller.ts index 554e0617591574ce5c34b3dff8b5fdbaacab4ca4..73fda22e699f5702b1616360bd7e95f0ac8aeb10 100644 --- a/src/score/score.controller.ts +++ b/src/score/score.controller.ts @@ -26,4 +26,11 @@ export class ScoreController { async scoreTick(@Param('id') gameId: GameEntity) { return this.scoreService.scoreTick(gameId); } + + // shows scores, :id is gameId + @Get('get-score/:id') + @GameStates('STARTED') + async getScores(@Param('id') gameId: GameEntity) { + return this.scoreService.getScores(gameId); + } } diff --git a/src/score/score.service.ts b/src/score/score.service.ts index aed55353afcbbbba37be2f84c38239d8d4b4fc07..dba8e6e79206322a4dffae937b5af6b2bdd89041 100644 --- a/src/score/score.service.ts +++ b/src/score/score.service.ts @@ -85,6 +85,31 @@ export class ScoreService { message: 'Scores added', }; } + + async getScores(gameId: GameEntity) { + // find games factions + const factions = await this.factionRepository.find({ + where: {game: gameId,}, + relations: ['game'], + }); + let scores = []; + await Promise.all( + factions.map(async factionNow => { + let score = await this.scoreRepository.findOne({ + where: {faction: factionNow}, + relations: ['faction'], + order: {scoreTimeStamp: 'DESC'}, + }); + //if score was found, put info to scores array + if (score.faction) { + let index = await scores.findIndex( + i => i.faction === score.faction, + ); + scores.push(score); + } + })) + return scores; + } } // // Hae kaikki Objective pointit