From 0cb15cee4394e74d42bd9f2a4b53de586b1c4a26 Mon Sep 17 00:00:00 2001 From: L4168 <L4168@student.jamk.fi> Date: Fri, 5 Jul 2019 09:13:24 +0300 Subject: [PATCH] added GameStates Guard --- src/faction/faction.controller.ts | 19 ++++++++++++++----- src/game/game.controller.ts | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/faction/faction.controller.ts b/src/faction/faction.controller.ts index 734e9d8..98fcc85 100644 --- a/src/faction/faction.controller.ts +++ b/src/faction/faction.controller.ts @@ -21,7 +21,7 @@ import { JoinGameGroupDTO, } from './faction.dto'; import { FactionService } from './faction.service'; -import { Roles } from '../shared/guard.decorator'; +import { Roles, GameStates } from '../shared/guard.decorator'; @Controller('faction') export class FactionController { @@ -30,6 +30,7 @@ export class FactionController { // takes gameId from the url to verify user role @Post('create-group/:id') @Roles('soldier') + @GameStates('CREATED') @UsePipes(new ValidationPipe()) async createGroup( @User('id') person, @@ -50,6 +51,7 @@ export class FactionController { // takes gameId from the url to verify user role @Put('join-group/:id') @Roles('soldier') + @GameStates('CREATED') async joinGroup( @User('id') person, @Param('id') id, @@ -66,17 +68,24 @@ export class FactionController { // param game ID is passed to @Roles @Put('promote/:id') - @UseGuards(new AuthGuard()) - @UsePipes(new ValidationPipe()) @Roles('admin') + @GameStates('CREATED') + @UsePipes(new ValidationPipe()) promotePlayer(@Param('id') game, @Body() body: PromotePlayerDTO) { return this.factionservice.promotePlayer(body); } - @Put('join-faction') + // used to join a faction + // :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') @UsePipes(new ValidationPipe()) - joinFaction(@User('id') person, @Body() data: JoinFactionDTO) { + joinFaction( + @User('id') person, + @Param('id') game, + @Body() data: JoinFactionDTO, + ) { return this.factionservice.joinFaction(person, data); } } diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts index 7cd7a4f..24d42bb 100644 --- a/src/game/game.controller.ts +++ b/src/game/game.controller.ts @@ -70,6 +70,7 @@ export class GameController { } @Post('flag/:id') + @GameStates('STARTED') async flagboxEvent(@Param('id') id: string, @Body() data: FlagboxEventDTO) { return this.gameservice.flagboxEvent(id, data); } -- GitLab