class validator ignored nested object for DTO in Nest js

79 views Asked by At
export class ClaimData {
  @IsString()
  @IsDefined()
  readonly network: string;

  @IsString()
  @IsDefined()
  readonly totalSupply: number;
}

export class UpdatePullStateDTO {
  @IsString()
  @IsDefined()
  @IsEnum(PullStates)
  readonly state: PullStates;

  @ValidateNested()
  @IsNotEmpty()
  @Type(() => ClaimData)
  @IsOptional()
  claimData?: ClaimData;
}

class validator ignores the claimData request body.

I enter a request like this in Postman with this body:

{
     "state": "completed",
     "claimData": {}
}

he misses it, although he should have checked the fields inside claimData.

I've read problems with this on the internet, but haven't found a solution. Even adding @ValidateNested and @Type didn't help.

0

There are 0 answers