#Nest js validation failing

4 messages · Page 1 of 1 (latest)

fierce siren
#

Patient intake dto

  @IsIn(['doc', 'image'])
  @IsNotEmpty()
  @ApiProperty({ example: 'doc', enum: FileType })
  type: FileType;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    example: 'https://mentalhealthai.s3.amazonaws.com/sample.jpeg',
  })
  file: string;

  @IsUUID()
  @IsNotEmpty()
  @ApiProperty({
    example: '6f1bf9f2-3f09-465b-9884-d657261687f5',
  })
  report_type_id: string;
}```
#

Patient intake dto with file

  @IsOptional()
  @ApiPropertyOptional({ type: 'string', format: 'binary' })
  file?: Express.Multer.File;
}```
#

Here is my controller

  @UseInterceptors(FileInterceptor('file'))
  @ApiConsumes('multipart/form-data')
  @ApiBody({ type: PatientIntakeWithFileDto })
  @ApiOperation({ summary: 'Patient intake form' })
  @Post('intake')
  savePatientIntake(
    @GetPatient()
    doctorPatientId: PatientTokenPayload,
    @Body() dto: PatientIntakeDto,
    @Req() request: Request,
    @UploadedFile(
      new ParseFilePipeBuilder()
        .addFileTypeValidator({
          fileType: /image\/(jpg|jpeg)$/i,
        })
        .addMaxSizeValidator({
          maxSize: 5 * 1024 * 1024,
        })
        .build({
          fileIsRequired: false,
          errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
        }),
    )
    file?: Express.Multer.File,
  ) {
    return this.patientrecordService.savePatientIntake(
      doctorPatientId,
      dto,
      request,
      file,
    );
  }```
#

I am getting error like this

    "message": [
        "files.0.property type should not exist",
        "files.0.property file should not exist",
        "files.0.property report_type_id should not exist",
        "files.1.property type should not exist",
        "files.1.property file should not exist",
        "files.1.property report_type_id should not exist"
    ],
    "error": "Bad Request",
    "statusCode": 400
}```