Code owners
Assign users and groups as approvers for specific file changes. Learn more.
game.controller.ts 1.98 KiB
import {
Controller,
Post,
UseGuards,
Body,
Get,
Param,
UsePipes,
Put,
UseInterceptors,
ClassSerializerInterceptor,
} from '@nestjs/common';
import { GameService } from './game.service';
import { AuthGuard } from '../shared/auth.guard';
import { User } from '../user/user.decorator';
import { GameDTO, FlagboxEventDTO, GameStateDTO } from './game.dto';
import { ValidationPipe } from '../shared/validation.pipe';
import { Roles, GameStates } from '../shared/guard.decorator';
import { GameEntity } from './game.entity';
@Controller('game')
export class GameController {
constructor(private gameservice: GameService) {}
@Post('new')
@UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe())
async newGame(@User('id') person, @Body() body: GameDTO) {
return this.gameservice.createNewGame(person, body);
}
@Put('edit/:id')
@Roles('admin')
@GameStates('CREATED')
@UsePipes(new ValidationPipe())
async editGame(@Param('id') id: string, @Body() body: GameDTO) {
return this.gameservice.editGame(id, body);
}
@Put('edit-state/:id')
@Roles('admin')
@UsePipes(new ValidationPipe())
async updateGameState(@Param('id') id: string, @Body() body: GameStateDTO) {
return this.gameservice.updateGameStatus(body);
}
@Get('listgames')
async listGames() {
return this.gameservice.listGames();
}
// ClassSerializerInterceptor removes excluded columns set in Entities
@UseInterceptors(ClassSerializerInterceptor)
@Get(':id')
async returnGameInfo(@Param('id') id: string) {
return this.gameservice.returnGameInfo(id);
}
@Get('get-factions/:id')
@Roles('admin')
async returnGameFactions(@Param('id') id: GameEntity) {
return this.gameservice.listFactions(id);
}
@Get('flag/:id')
async flagboxQuery(@Param('id') id: string) {
return this.gameservice.flagboxQuery(id);
}
@Post('flag/:id')
async flagboxEvent(@Param('id') id: string, @Body() data: FlagboxEventDTO) {
return this.gameservice.flagboxEvent(id, data);
}
}