From 3bd5bcb383bddbd5299d29c844de0a87516c5977 Mon Sep 17 00:00:00 2001
From: L4168 <L4168@student.jamk.fi>
Date: Thu, 27 Jun 2019 11:45:09 +0300
Subject: [PATCH] validation for services

---
 src/task/task.dto.ts | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/task/task.dto.ts b/src/task/task.dto.ts
index aa3238f..723ddd7 100644
--- a/src/task/task.dto.ts
+++ b/src/task/task.dto.ts
@@ -1,30 +1,38 @@
 import {
   IsString,
   Length,
-  IsNumber,
   IsBoolean,
-  Min,
-  Max,
+  Validate,
+  IsUUID,
+  Equals,
 } from 'class-validator';
-import { FactionEntity } from 'src/game/faction.entity';
+import { FactionEntity } from '../game/faction.entity';
+import { Uuid } from '../shared/uuid.validation';
+import { GameEntity } from 'src/game/game.entity';
 
-export class TaskDTO {
+export class CreateTaskDTO {
   @IsString()
   @Length(3, 31)
   taskName: string;
   @IsString()
   @Length(0, 255)
   taskDescription: string;
-  @IsNumber()
-  @Min(1)
-  @Max(99)
-  taskScore: number;
-  @IsString()
-  @Length(3, 31)
-  taskWinner?: string;
   @IsBoolean()
   taskIsActive: boolean;
-  // faction unique id
-  @IsString()
+  @Validate(Uuid)
   faction: FactionEntity;
+  @Equals(null)
+  taskWinner: FactionEntity;
+  // faction unique id
+  @IsUUID('4')
+  taskGame: GameEntity;
+}
+
+export class EditTaskDTO {
+  @IsUUID('4')
+  taskId: string;
+  @IsUUID('4')
+  taskWinner: FactionEntity;
+  @IsUUID('4')
+  taskGame: GameEntity;
 }
-- 
GitLab