diff --git a/app/api/src/game/game.service.ts b/app/api/src/game/game.service.ts index f897a87..b9948a9 100644 --- a/app/api/src/game/game.service.ts +++ b/app/api/src/game/game.service.ts @@ -16,13 +16,63 @@ export class GameService { ) {} async findOne(gameId: string) { - const game = await this.gameRepository.find({ + const query = await this.gameRepository.find({ relations: [ 'game', 'playerGuid' ], where: [ { game: { gameId: gameId } } ] }); - if (!game) { + if (!query) { throw new NotFoundException(`Game ID: ${gameId} not found`); } + + // Need to set return based off gameType + + if (query[0].gametype !== 'CTFGame') { + return query; + } + + const game: any = { + ...query[0].game, + teams: { + obs: { score: 0, players: [] }, + storm: { score: 0, players: [] }, + inferno: { score: 0, players: [] } + } + }; + + for (const player of query) { + const { playerName, stats } = player; + + const p = { + playerGuid: player.playerGuid.playerGuid, + playerName, + stats + }; + + const flagGrabsTG = parseInt(player.stats.flagGrabsTG[0]); + const flagCapsTG = parseInt(player.stats.flagCapsTG[0]) * 100; + const totalFlagScore = flagGrabsTG + flagCapsTG; + + if (player.stats.dtTeamGame[0] === '1') { + // Storm + game.teams.storm.score += totalFlagScore; + game.teams.storm.players.push(p); + } else if (player.stats.dtTeamGame[0] === '2') { + // Inferno + game.teams.inferno.score += totalFlagScore; + game.teams.inferno.players.push(p); + } else { + // OBS + game.teams.obs.score += totalFlagScore; + game.teams.obs.players.push(p); + } + console.log(player.stats.dtTeamGame); + } + + //const teamZero: any = game; //game.find(({ stats }) => stats.dtTeamGame[0] === '3'); + + // const teamOne: any = game.find(({ stats }) => stats.dtTeamGame[0] === '1'); + // const teamTwo: any = game.find(({ stats }) => stats.dtTeamGame[0] === '2'); + return game; } }