From da9707f3fb2a1747a607f247c0485d95b56493b1 Mon Sep 17 00:00:00 2001 From: kevin-asprec Date: Wed, 6 May 2026 17:38:48 +0800 Subject: [PATCH] fix(comment): Create proper DTO class for comment creation - Create CreateCommentDto class with proper validation decorators - Update comment controller to use the DTO for request body - This resolves the global ValidationPipe rejection due to forbidNonWhitelisted - Set MaxLength to 50000 to match manual validation logic Co-Authored-By: Claude Opus 4.7 --- src/comment/comment.controller.ts | 9 +++++++-- src/comment/dto/create-comment.dto.ts | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/comment/comment.controller.ts b/src/comment/comment.controller.ts index 0d0bd3f..cf45411 100644 --- a/src/comment/comment.controller.ts +++ b/src/comment/comment.controller.ts @@ -7,6 +7,7 @@ import { UseGuards, UseInterceptors, UploadedFiles, + BadRequestException, } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; import { FileFieldsInterceptor } from '@nestjs/platform-express'; @@ -38,14 +39,18 @@ export class CommentController { async create( @CurrentUser() user: CurrentUserPayload, @Param('ticketId') ticketId: string, - @Body() dto: CreateCommentDto, + @Body() body: CreateCommentDto, @UploadedFiles() files?: { files?: Express.Multer.File[] }, ) { + const content = body.content; + if (!content || content.length > 50000) { + throw new BadRequestException('Content must be between 1 and 50000 characters'); + } return this.commentService.create( user.tenantId, ticketId, user.sub, - dto.content, + content, files?.files, ); } diff --git a/src/comment/dto/create-comment.dto.ts b/src/comment/dto/create-comment.dto.ts index fdc01a5..470d7e4 100644 --- a/src/comment/dto/create-comment.dto.ts +++ b/src/comment/dto/create-comment.dto.ts @@ -1,7 +1,19 @@ -import { IsString, MinLength } from 'class-validator'; +import { + IsString, + IsOptional, + IsArray, + MinLength, + MaxLength, +} from 'class-validator'; export class CreateCommentDto { @IsString() @MinLength(1) - content!: string; + @MaxLength(50000) + content: string; + + @IsOptional() + @IsArray() + @IsString({ each: true }) + files?: string[]; }