From 425eaa78d3b2d752d25e35c6647ab6fd0458b9bf Mon Sep 17 00:00:00 2001 From: Samuli Virtapohja <l4721@student.jamk.fi> Date: Tue, 9 Jul 2019 16:42:34 +0300 Subject: [PATCH] changes to formatting --- src/tracking/tracking.controller.ts | 10 ++++++++++ src/tracking/tracking.module.ts | 5 ++++- src/tracking/tracking.service.ts | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/tracking/tracking.controller.ts b/src/tracking/tracking.controller.ts index 8049173..0ccbb85 100644 --- a/src/tracking/tracking.controller.ts +++ b/src/tracking/tracking.controller.ts @@ -6,6 +6,8 @@ import { UsePipes, Body, Get, + UseInterceptors, + ClassSerializerInterceptor, } from '@nestjs/common'; import { TrackingService } from './tracking.service'; @@ -38,4 +40,12 @@ export class TrackingController { async getPlayerLocations(@User('id') userId, @Param('id') gameId) { return this.trackingservice.getPlayers(userId, gameId); } + + @Get('player/:id') + @Roles('admin', 'factionleader') + @GameStates('STARTED', 'PAUSED') + @UseInterceptors(ClassSerializerInterceptor) + async getPlayerData(@User('id') userId, @Param('id') gameid, @Body() person) { + return this.trackingservice.getPlayerData(person); + } } diff --git a/src/tracking/tracking.module.ts b/src/tracking/tracking.module.ts index 45b167f..fe31de3 100644 --- a/src/tracking/tracking.module.ts +++ b/src/tracking/tracking.module.ts @@ -5,9 +5,12 @@ import { TrackingController } from './tracking.controller'; import { TrackingService } from './tracking.service'; import { TrackingEntity } from './tracking.entity'; import { Game_PersonEntity } from '../game/game.entity'; +import { PersonEntity } from '../user/user.entity'; @Module({ - imports: [TypeOrmModule.forFeature([TrackingEntity, Game_PersonEntity])], + imports: [ + TypeOrmModule.forFeature([TrackingEntity, Game_PersonEntity, PersonEntity]), + ], controllers: [TrackingController], providers: [TrackingService], }) diff --git a/src/tracking/tracking.service.ts b/src/tracking/tracking.service.ts index fb4eab0..3c64534 100644 --- a/src/tracking/tracking.service.ts +++ b/src/tracking/tracking.service.ts @@ -6,6 +6,7 @@ import { Game_PersonEntity } from '../game/game.entity'; import { TrackingEntity } from './tracking.entity'; import { TrackingDTO } from './tracking.dto'; import { FactionEntity } from '../faction/faction.entity'; +import { PersonEntity } from '../user/user.entity'; @Injectable() export class TrackingService { @@ -14,6 +15,8 @@ export class TrackingService { private trackingrepository: Repository<TrackingEntity>, @InjectRepository(Game_PersonEntity) private gamepersonrepository: Repository<Game_PersonEntity>, + @InjectRepository(PersonEntity) + private personrepository: Repository<PersonEntity>, ) {} async trackLocation(personId, gameId, trackdata: TrackingDTO) { @@ -95,6 +98,25 @@ export class TrackingService { return currentdata; } + // get selected player data + async getPlayerData(person) { + const gameperson = await this.gamepersonrepository.findOne({ + where: { gamepersonId: person.gamepersonId }, + relations: ['person', 'leaderGroup', 'group', 'faction'], + }); + if (!gameperson) { + throw new HttpException('No player found!', HttpStatus.BAD_REQUEST); + } + + return { + gamepersonId: gameperson.gamepersonId, + name: gameperson.person.name, + role: gameperson.role, + group: gameperson.group, + faction: gameperson.faction.factionName, + }; + } + private async mapFunction(data): Promise<Number> { return await data.map(type => { return type; -- GitLab