From 759d8afddfc34bb733ae07c67a8ac1bb92733ad6 Mon Sep 17 00:00:00 2001 From: JoepieSnels Date: Mon, 5 Jan 2026 12:22:10 +0100 Subject: [PATCH] create works now with validation --- .../controllers/modules.controller.ts | 4 ++-- src/presentation/dtos/choiceModule.dto.ts | 8 ++++--- src/presentation/dtos/location.dto.ts | 22 +++++++++++++++++++ src/presentation/dtos/moduleTag.dto.ts | 22 +++++++++++++++++++ 4 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/presentation/dtos/location.dto.ts create mode 100644 src/presentation/dtos/moduleTag.dto.ts diff --git a/src/presentation/controllers/modules.controller.ts b/src/presentation/controllers/modules.controller.ts index c21dfd6..391a8d1 100644 --- a/src/presentation/controllers/modules.controller.ts +++ b/src/presentation/controllers/modules.controller.ts @@ -105,8 +105,8 @@ export class ModulesController { throw new UnauthorizedException('Study credits must be 15 or 30'); } - if (moduleData.level !== 'NFQL5' && moduleData.level !== 'NFQL6') { - throw new UnauthorizedException('Level must be NFQL5 or NFQL6'); + if (moduleData.level !== 'NLQF5' && moduleData.level !== 'NLQF6') { + throw new UnauthorizedException('Level must be NLQF5 or NLQF6'); } const module = await this.moduleService.createModule(moduleData); diff --git a/src/presentation/dtos/choiceModule.dto.ts b/src/presentation/dtos/choiceModule.dto.ts index d02cfd6..b8aef84 100644 --- a/src/presentation/dtos/choiceModule.dto.ts +++ b/src/presentation/dtos/choiceModule.dto.ts @@ -1,4 +1,7 @@ import { ApiProperty } from '@nestjs/swagger'; +import { LocationDTO } from './location.dto'; +import { ModuleTagDTO } from './moduleTag.dto'; +import { Type } from 'class-transformer'; import { IsString, IsNumber, @@ -7,7 +10,6 @@ import { MinLength, Min, IsDateString, - IsObject, } from 'class-validator'; export class CreateModuleDTO { @@ -40,12 +42,12 @@ export class CreateModuleDTO { @ApiProperty() @IsArray() - @IsObject({ each: true }) + @Type(() => LocationDTO) location: { id: string; name: string }[]; @ApiProperty() @IsArray() - @IsObject({ each: true }) + @Type(() => ModuleTagDTO) moduleTags: { id: string; name: string }[]; @ApiProperty() diff --git a/src/presentation/dtos/location.dto.ts b/src/presentation/dtos/location.dto.ts new file mode 100644 index 0000000..34ab772 --- /dev/null +++ b/src/presentation/dtos/location.dto.ts @@ -0,0 +1,22 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { Type } from 'class-transformer'; +import { + IsString, + IsNumber, + IsArray, + IsNotEmpty, + MinLength, + Min, + IsDateString, +} from 'class-validator'; + +export class LocationDTO { + @ApiProperty() + @IsString() + @IsNotEmpty() + id: string; + @ApiProperty() + @IsString() + @IsNotEmpty() + name: string; +} diff --git a/src/presentation/dtos/moduleTag.dto.ts b/src/presentation/dtos/moduleTag.dto.ts new file mode 100644 index 0000000..40c57bc --- /dev/null +++ b/src/presentation/dtos/moduleTag.dto.ts @@ -0,0 +1,22 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { Type } from 'class-transformer'; +import { + IsString, + IsNumber, + IsArray, + IsNotEmpty, + MinLength, + Min, + IsDateString, +} from 'class-validator'; +export class ModuleTagDTO { + @ApiProperty() + @IsString() + @IsNotEmpty() + id: string; + + @ApiProperty() + @IsString() + @IsNotEmpty() + name: string; +}