diff --git a/src/faction/faction.entity.ts b/src/faction/faction.entity.ts index bc0b9269bdc5618364c536632f226c4974877080..4a8f63a06fb61dccc8fad65f6fe987ec16323f35 100644 --- a/src/faction/faction.entity.ts +++ b/src/faction/faction.entity.ts @@ -13,6 +13,7 @@ import { GameEntity } from '../game/game.entity'; import { Game_PersonEntity } from '../game/game.entity'; import { MapDrawingEntity } from '../draw/coordinate.entity'; import { Exclude } from 'class-transformer'; +import { ScoreEntity } from 'src/score/score.entity'; //Faction, PowerUp, Faction_powerUp, FP_History, Score @@ -35,6 +36,10 @@ export class FactionEntity { game: GameEntity; @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction) mapDrawings: MapDrawingEntity[]; + @OneToMany(type => ScoreEntity, score => score.scoreId, { + onDelete: 'NO ACTION', + }) + scores: ScoreEntity[]; factionObject() { const { factionId, factionName, game } = this; diff --git a/src/replay/replay.controller.ts b/src/replay/replay.controller.ts index acc2ef50dafc1fb1c7f193c8da4834162b6ff4be..ed23960549f32e8b76e21b72dfb4693a7f389224 100644 --- a/src/replay/replay.controller.ts +++ b/src/replay/replay.controller.ts @@ -1,12 +1,19 @@ -import { Controller, Get, Param, Post } from '@nestjs/common'; +import { + Controller, + Get, + Param, + Post, + UseInterceptors, + ClassSerializerInterceptor, +} from '@nestjs/common'; import { ReplayService } from './replay.service'; -import { Roles } from 'src/shared/guard.decorator'; @Controller('replay') export class ReplayController { constructor(private replayservice: ReplayService) {} @Get(':id') + @UseInterceptors(ClassSerializerInterceptor) async replayInfo(@Param('id') gameId) { return this.replayservice.replayData(gameId); } diff --git a/src/replay/replay.module.ts b/src/replay/replay.module.ts index c7accefa55f867a49c36e2dbc5cc3e75563b211c..b5dc7c888da8806ecae546a7dd5aecfcc7f10dae 100644 --- a/src/replay/replay.module.ts +++ b/src/replay/replay.module.ts @@ -8,8 +8,12 @@ import { FactionEntity, GameGroupEntity } from '../faction/faction.entity'; import { UserService } from '../user/user.service'; import { FactionService } from '../faction/faction.service'; import { TrackingService } from '../tracking/tracking.service'; -import { TrackingEntity } from 'src/tracking/tracking.entity'; -import { PersonEntity } from 'src/user/user.entity'; +import { TrackingEntity } from '../tracking/tracking.entity'; +import { PersonEntity } from '../user/user.entity'; +import { + MapDrawingEntity, + MapDrawingHistoryEntity, +} from '../draw/coordinate.entity'; @Module({ imports: [ @@ -20,6 +24,8 @@ import { PersonEntity } from 'src/user/user.entity'; TrackingEntity, GameGroupEntity, Game_PersonEntity, + MapDrawingEntity, + MapDrawingHistoryEntity, ]), ], controllers: [ReplayController], diff --git a/src/replay/replay.service.ts b/src/replay/replay.service.ts index f5430860112e243305a4f0542036b8f9a0bb8a0a..2f9562581f5d9e4b3ad3e9a8627f27a15c143557 100644 --- a/src/replay/replay.service.ts +++ b/src/replay/replay.service.ts @@ -4,11 +4,15 @@ import { Repository } from 'typeorm'; import * as jwt from 'jsonwebtoken'; import { FactionEntity } from '../faction/faction.entity'; -import { GameEntity } from 'src/game/game.entity'; -import { TrackingService } from 'src/tracking/tracking.service'; -import { UserService } from 'src/user/user.service'; -import { FactionService } from 'src/faction/faction.service'; -import { TrackingEntity } from 'src/tracking/tracking.entity'; +import { GameEntity } from '../game/game.entity'; +import { TrackingService } from '../tracking/tracking.service'; +import { UserService } from '../user/user.service'; +import { FactionService } from '../faction/faction.service'; +import { TrackingEntity } from '../tracking/tracking.entity'; +import { + MapDrawingEntity, + MapDrawingHistoryEntity, +} from '../draw/coordinate.entity'; @Injectable() export class ReplayService { @@ -19,17 +23,31 @@ export class ReplayService { private gameRepository: Repository<GameEntity>, @InjectRepository(TrackingEntity) private trackingRepository: Repository<TrackingEntity>, + @InjectRepository(MapDrawingEntity) + private mapdrawingRepository: Repository<MapDrawingEntity>, + @InjectRepository(MapDrawingHistoryEntity) + private mapHistoryRepository: Repository<MapDrawingHistoryEntity>, private trackingService: TrackingService, private userService: UserService, private factionService: FactionService, ) {} async replayData(gameId) { - const replay = await this.factionRepository.find({ - where: { game: gameId }, - relations: ['mapDrawings', 'scores', 'trackdata'], + let mapDrawingIds = await this.mapdrawingRepository.find({ + where: { gameId: gameId }, + select: ['mapDrawingId'], }); - return replay; + let drawings = []; + await Promise.all( + mapDrawingIds.map(async mapId => { + drawings.push( + await this.mapHistoryRepository.find({ + mapdrawing: mapId.mapDrawingId, + }), + ); + }), + ); + return drawings; } // get replay data for players diff --git a/src/score/score.service.ts b/src/score/score.service.ts index 640970c8e5ca99e877982cc2f4174123595792bb..90716c4b2e9f5d72f21971edb574972a2ccfda6d 100644 --- a/src/score/score.service.ts +++ b/src/score/score.service.ts @@ -69,7 +69,8 @@ export class ScoreService { i => i.faction === current.owner.factionId, ); index !== -1 - ? await (scoreData[index]['score'] += box.objectivePointMultiplier * current.owner.multiplier) + ? await (scoreData[index]['score'] += + box.objectivePointMultiplier * current.owner.multiplier) : await scoreData.push({ score: box.objectivePointMultiplier, faction: current.owner.factionId,