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

baselogic for factionleader and admin added

parent 0cb0ae88
No related branches found
No related tags found
3 merge requests!59Development to master,!36Development,!34Get player location
......@@ -5,6 +5,7 @@ import {
UseGuards,
UsePipes,
Body,
Get,
} from '@nestjs/common';
import { TrackingService } from './tracking.service';
......@@ -30,4 +31,11 @@ export class TrackingController {
) {
return this.trackingservice.trackLocation(userId, id, trackdata);
}
@Get('players/:id')
@Roles('admin', 'factionleader')
@GameStates('STARTED', 'PAUSED')
async getPlayerLocations(@User('id') userId, @Param('id') gameId) {
return this.trackingservice.getPlayers(userId, gameId);
}
}
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm';
import { Game_PersonEntity } from '../game/game.entity';
import { FactionEntity } from 'src/faction/faction.entity';
@Entity('Tracking')
export class TrackingEntity {
......@@ -7,4 +8,6 @@ export class TrackingEntity {
@Column({ type: 'json', nullable: true }) data: JSON;
@ManyToOne(type => Game_PersonEntity, person => person.gamepersonId)
gamepersonId: Game_PersonEntity;
@ManyToOne(type => FactionEntity, faction => faction.factionId)
faction: FactionEntity;
}
......@@ -5,6 +5,7 @@ import { Repository } from 'typeorm';
import { Game_PersonEntity } from '../game/game.entity';
import { TrackingEntity } from './tracking.entity';
import { TrackingDTO } from './tracking.dto';
import { FactionEntity } from '../faction/faction.entity';
@Injectable()
export class TrackingService {
......@@ -55,6 +56,22 @@ export class TrackingService {
}
}
// get player data while game is running
async getPlayers(userId, gameId) {
// get gameperson
const gameperson = await this.gamepersonrepository.findOne({
where: { person: userId, game: gameId },
relations: ['faction'],
});
// if faction is not null, user is factionleader
if (gameperson.faction) {
return 'factionleader';
} else {
return 'admin';
}
}
private async mapFunction(data): Promise<Number> {
return await data.map(type => {
return type;
......
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