diff --git a/src/faction/faction.controller.ts b/src/faction/faction.controller.ts index 98fcc856d6a5e1cb469e81249eea044df4011877..82e29d33979cc73941144bf7535ae07eb63dfb2c 100644 --- a/src/faction/faction.controller.ts +++ b/src/faction/faction.controller.ts @@ -79,7 +79,7 @@ export class FactionController { // :id is the id of the game, and is needed for GameStates to check the state of the game @Put('join-faction/:id') @UseGuards(new AuthGuard()) - @GameStates('CREATED') + @GameStates('CREATED', 'STARTED') @UsePipes(new ValidationPipe()) joinFaction( @User('id') person, diff --git a/src/tracking/tracking.service.ts b/src/tracking/tracking.service.ts index cb44c4ff3cd12be7155df1c5575683e6ce374f0f..fb4eab054b0a53d4fcc2481c21e28a1adcf257a0 100644 --- a/src/tracking/tracking.service.ts +++ b/src/tracking/tracking.service.ts @@ -19,8 +19,8 @@ export class TrackingService { async trackLocation(personId, gameId, trackdata: TrackingDTO) { // find player let gameperson = await this.gamepersonrepository.findOne({ - game: gameId, - person: personId, + where: { game: gameId, person: personId }, + relations: ['faction'], }); if (!gameperson) { throw new HttpException( @@ -51,6 +51,8 @@ export class TrackingService { // initialize timestamp trackdata.data['geometry']['properties']['time'] = []; trackedperson = await this.trackingrepository.create(trackdata); + trackedperson.faction = gameperson.faction; + trackedperson.game = gameId; trackedperson.gamepersonId = gameperson; return await this.trackingrepository.save(trackedperson); } @@ -64,18 +66,33 @@ export class TrackingService { relations: ['faction'], }); - // if user , user is factionleader + let playerdata; + // get playerdata if (gameperson.faction) { - const playerdata = await this.trackingrepository.find({ + playerdata = await this.trackingrepository.find({ where: { faction: gameperson.faction }, + relations: ['faction', 'gamepersonId'], }); - return playerdata; } else { - const playerdata = await this.trackingrepository.find({ + playerdata = await this.trackingrepository.find({ where: { game: gameId }, + relations: ['faction', 'gamepersonId'], }); - return 'admin'; } + + // parse data + const currentdata = await Promise.all( + playerdata.map(async player => { + return { + gamepersonId: player['gamepersonId']['gamepersonId'], + gamepersonRole: player['gamepersonId']['role'], + factionId: player['faction']['factionId'], + coordinates: player['data']['geometry']['coordinates'].pop(), + }; + }), + ); + + return currentdata; } private async mapFunction(data): Promise<Number> {