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 9dad4e965ae797b31a2f708a7008048556db0992..625ca7a4e79e894f61b264488835f34b150f713e 100644 --- a/src/score/score.service.ts +++ b/src/score/score.service.ts @@ -87,6 +87,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