Skip to content
Snippets Groups Projects
Commit 8e92a18e authored by L4072's avatar L4072
Browse files

getScore works

parent f6b9bbe9
No related branches found
No related tags found
3 merge requests!59Development to master,!36Development,!35getScore works
...@@ -26,4 +26,11 @@ export class ScoreController { ...@@ -26,4 +26,11 @@ export class ScoreController {
async scoreTick(@Param('id') gameId: GameEntity) { async scoreTick(@Param('id') gameId: GameEntity) {
return this.scoreService.scoreTick(gameId); 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);
}
} }
...@@ -87,6 +87,31 @@ export class ScoreService { ...@@ -87,6 +87,31 @@ export class ScoreService {
message: 'Scores added', 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 // Hae kaikki Objective pointit
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment