diff --git a/src/tracking/tracking.controller.ts b/src/tracking/tracking.controller.ts index dbab7955f4cf8a90718b7ea0e5138173cbbe7e31..2b409cee30764f1d0d33133828a5fd9f9d47d31f 100644 --- a/src/tracking/tracking.controller.ts +++ b/src/tracking/tracking.controller.ts @@ -1,4 +1,14 @@ -import { Controller, Post, Param, UsePipes, Body, Get } from '@nestjs/common'; +import { + Controller, + Post, + Param, + UseGuards, + UsePipes, + Body, + Get, + UseInterceptors, + ClassSerializerInterceptor, +} from '@nestjs/common'; import { TrackingService } from './tracking.service'; import { User } from '../user/user.decorator'; @@ -31,4 +41,12 @@ export class TrackingController { async getPlayerLocations(@GamePerson() gameperson, @Param('id') gameId) { return this.trackingservice.getPlayers(gameperson, 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 4f6c2244473da2d9a80f63f5e1411fe6ae160d50..fe31de3704dcd39113f8a46f6f718555a0528b2b 100644 --- a/src/tracking/tracking.module.ts +++ b/src/tracking/tracking.module.ts @@ -4,9 +4,13 @@ import { TypeOrmModule } from '@nestjs/typeorm'; 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])], + 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 446d0167c48f7951320c49f5976ad495e37f8fec..23944563b4f58e9f1bd54f2428a1bf7dbec3e67b 100644 --- a/src/tracking/tracking.service.ts +++ b/src/tracking/tracking.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; @@ -11,6 +11,8 @@ export class TrackingService { constructor( @InjectRepository(TrackingEntity) private trackingrepository: Repository<TrackingEntity>, + @InjectRepository(Game_PersonEntity) + private gamepersonrepository: Repository<Game_PersonEntity>, ) {} async trackLocation( @@ -75,4 +77,27 @@ 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: { + factionId: gameperson.faction.factionId, + factionName: gameperson.faction.factionName, + colour: gameperson.faction.colour, + }, + }; + } }