Skip to content
Snippets Groups Projects
Commit 411caf41 authored by Samuli Virtapohja's avatar Samuli Virtapohja
Browse files

merge specific to dev

parents c47128bd cf1fbbf4
No related branches found
No related tags found
3 merge requests!59Development to master,!48Development,!45Specificplayer to Development
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 { TrackingService } from './tracking.service';
import { User } from '../user/user.decorator'; import { User } from '../user/user.decorator';
...@@ -31,4 +41,12 @@ export class TrackingController { ...@@ -31,4 +41,12 @@ export class TrackingController {
async getPlayerLocations(@GamePerson() gameperson, @Param('id') gameId) { async getPlayerLocations(@GamePerson() gameperson, @Param('id') gameId) {
return this.trackingservice.getPlayers(gameperson, 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);
}
} }
...@@ -4,9 +4,13 @@ import { TypeOrmModule } from '@nestjs/typeorm'; ...@@ -4,9 +4,13 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { TrackingController } from './tracking.controller'; import { TrackingController } from './tracking.controller';
import { TrackingService } from './tracking.service'; import { TrackingService } from './tracking.service';
import { TrackingEntity } from './tracking.entity'; import { TrackingEntity } from './tracking.entity';
import { Game_PersonEntity } from '../game/game.entity';
import { PersonEntity } from '../user/user.entity';
@Module({ @Module({
imports: [TypeOrmModule.forFeature([TrackingEntity])], imports: [
TypeOrmModule.forFeature([TrackingEntity, Game_PersonEntity, PersonEntity]),
],
controllers: [TrackingController], controllers: [TrackingController],
providers: [TrackingService], providers: [TrackingService],
}) })
......
import { Injectable } from '@nestjs/common'; import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
...@@ -11,6 +11,8 @@ export class TrackingService { ...@@ -11,6 +11,8 @@ export class TrackingService {
constructor( constructor(
@InjectRepository(TrackingEntity) @InjectRepository(TrackingEntity)
private trackingrepository: Repository<TrackingEntity>, private trackingrepository: Repository<TrackingEntity>,
@InjectRepository(Game_PersonEntity)
private gamepersonrepository: Repository<Game_PersonEntity>,
) {} ) {}
async trackLocation( async trackLocation(
...@@ -75,4 +77,27 @@ export class TrackingService { ...@@ -75,4 +77,27 @@ export class TrackingService {
return currentdata; 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,
},
};
}
} }
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