Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
draw.controller.ts 1.68 KiB
import {
  Controller,
  Put,
  Get,
  Param,
  UsePipes,
  ValidationPipe,
  Body,
  UseInterceptors,
  ClassSerializerInterceptor,
} from '@nestjs/common';

import { DrawService } from './draw.service';
import { Roles, GameStates } from '../shared/guard.decorator';
import { MapDrawingDTO } from './mapdrawing.dto';
import { GamePerson } from 'src/game/gameperson.decorator';

//////////////////////////////////////////////////////////////////////////
///     DrawController                                                 ///
///                                                                    ///
///     Functions either insert or return MapDrawing data,             ///
///     Insert functions require user to have proper role (either gm   ///
///     or commander) in the game to be able store the data:           ///
///     MapDrawingDTO data to database.                                ///
///     Data return functions require atleast spectator role.          ///
//////////////////////////////////////////////////////////////////////////

@Controller('draw')
export class DrawController {
  constructor(private drawService: DrawService) {}

  @Put('mapdrawing/:id')
  @Roles('admin', 'factionleader')
  @GameStates('CREATED', 'STARTED', 'PAUSED')
  @UsePipes(new ValidationPipe())
  async draw(
    @GamePerson() gameperson,
    @Param('id') gameId,
    @Body() data: MapDrawingDTO,
  ) {
    return this.drawService.draw(gameperson, gameId, data);
  }

  @Get('map/:id')
  @Roles('admin', 'factionleader', 'soldier', 'groupleader')
  @UseInterceptors(ClassSerializerInterceptor)
  async drawMap(@GamePerson() gameperson, @Param('id') gameId) {
    return this.drawService.drawMap(gameperson, gameId);
  }
}