Skip to content
Snippets Groups Projects
Commit 7b38a20d authored by L4168's avatar L4168
Browse files

added DTOs for draw

parent c5a17c37
No related branches found
No related tags found
3 merge requests!59Development to master,!36Development,!33Small fixes
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
import { AuthGuard } from '../shared/auth.guard'; import { AuthGuard } from '../shared/auth.guard';
import { DrawService } from './draw.service'; import { DrawService } from './draw.service';
import { Roles, GameStates } from '../shared/guard.decorator'; import { Roles, GameStates } from '../shared/guard.decorator';
import { MapDrawingDTO, ReturnDrawingsDTO } from './mapdrawing.dto';
/* /*
DrawController DrawController
...@@ -25,17 +26,17 @@ export class DrawController { ...@@ -25,17 +26,17 @@ export class DrawController {
constructor(private drawService: DrawService) {} constructor(private drawService: DrawService) {}
@Put('mapdrawing/:id') @Put('mapdrawing/:id')
@UsePipes(new ValidationPipe())
@Roles('admin', 'factionleader') @Roles('admin', 'factionleader')
@GameStates('CREATED', 'STARTED') @GameStates('CREATED', 'STARTED')
async draw(@Param('id') gameId, @Body() data) { @UsePipes(new ValidationPipe())
async draw(@Param('id') gameId, @Body() data: MapDrawingDTO) {
return this.drawService.draw(gameId, data); return this.drawService.draw(gameId, data);
} }
@Get('map/:id') @Get('map/:id')
@UseGuards(new AuthGuard()) @UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe()) @UsePipes(new ValidationPipe())
async drawMap(@Param('id') id, @Body() data) { async drawMap(@Param('id') id, @Body() data: ReturnDrawingsDTO) {
return this.drawService.drawMap(id, data); return this.drawService.drawMap(id, data);
} }
} }
...@@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm'; ...@@ -3,6 +3,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { MapDrawingEntity } from '../draw/coordinate.entity'; import { MapDrawingEntity } from '../draw/coordinate.entity';
import { MapDrawingDTO, ReturnDrawingsDTO } from './mapdrawing.dto';
@Injectable() @Injectable()
export class DrawService { export class DrawService {
...@@ -11,11 +12,9 @@ export class DrawService { ...@@ -11,11 +12,9 @@ export class DrawService {
private mapDrawingRepository: Repository<MapDrawingEntity>, private mapDrawingRepository: Repository<MapDrawingEntity>,
) {} ) {}
async draw(gameId, data: MapDrawingEntity) { async draw(gameId, data: MapDrawingDTO) {
data['gameId'] = gameId; data['gameId'] = gameId;
const drawing = await this.mapDrawingRepository.create(data); const drawing = await this.mapDrawingRepository.create(data);
if (data.mapDrawingId == null || data.mapDrawingId == '') { if (data.mapDrawingId == null || data.mapDrawingId == '') {
// luo uuden instanssin. // luo uuden instanssin.
const mapDrawing = await this.mapDrawingRepository.insert(drawing); const mapDrawing = await this.mapDrawingRepository.insert(drawing);
...@@ -27,13 +26,21 @@ export class DrawService { ...@@ -27,13 +26,21 @@ export class DrawService {
} }
// draw map based on game and // draw map based on game and
async drawMap(id, data: MapDrawingEntity) { async drawMap(id, data: ReturnDrawingsDTO) {
data['gameId'] = id;
data['drawingIsActive'] = true;
// get faction
const mapDrawings = await this.mapDrawingRepository.create(data);
// return mapdrawings with given faction and gameid // return mapdrawings with given faction and gameid
return await this.mapDrawingRepository.find(mapDrawings); return await this.mapDrawingRepository.find({
where: [
{
gameId: id,
faction: data.factionId,
drawingIsActive: true,
},
{
gameId: id,
faction: null,
drawingIsActive: true,
},
],
});
} }
} }
import { IsUUID } from 'class-validator'; import { IsUUID, IsOptional, IsBoolean, Allow } from 'class-validator';
import { GameDTO } from '../game/game.dto';
import { GameEntity, Game_PersonEntity } from '../game/game.entity';
import { FactionEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity';
import { FactionDTO } from '../faction/faction.dto'; import { GameEntity } from 'src/game/game.entity';
import { MapDrawingEntity } from '../draw/coordinate.entity';
export class MapDrawingDTO { export class MapDrawingDTO {
@IsOptional()
@IsUUID('4')
mapDrawingId: string;
@Allow()
data: JSON; data: JSON;
gameId: GameDTO; @IsOptional()
faction?: FactionDTO; @IsUUID('4')
isActive?: boolean; gameId: GameEntity;
validUntil?: string; @IsOptional()
@IsUUID('4')
faction?: FactionEntity;
@IsBoolean()
drawingIsActive?: boolean;
drawingValidTill?: string;
} }
export class DrawMapDTO { export class ReturnDrawingsDTO {
@IsOptional()
@IsUUID('4') @IsUUID('4')
mapDrawingId: MapDrawingEntity;
gameId: GameEntity;
factionId: FactionEntity; factionId: FactionEntity;
gamepersonId: Game_PersonEntity;
data: JSON;
} }
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