nestjs-form-data icon indicating copy to clipboard operation
nestjs-form-data copied to clipboard

Does not work with `ValidateIf` and `ValidateNested`

Open reeshabhranjan opened this issue 1 year ago • 3 comments

This is the DTO (excerpt from it):

{
...
	@IsArray()
	@ArrayMinSize(1)
	@ValidateIf((o) => o.type === AddHubElementTypes.AUDIO || o.type === AddHubElementTypes.GENERAL)
	@ValidateNested({ each: true })
	@Type(() => AudioUrlDto)
	@ApiProperty()
	@Transform(({ value }) => JSON.parse(value))
	audioUrls?: AudioUrlDto[];
...
}

This is the definition of AudioUrlDto:

export class AudioUrlDto {
	@IsEnum(HubPageAudioUrlType)
	@ApiProperty()
	type: HubPageAudioUrlType;

	@IsUrl()
	@ApiProperty()
	url: string;

	@IsInt()
	@ApiProperty()
	order: number;
}

This is what I send: image

I receive a 500 error because the audioUrls array was not properly validated.

reeshabhranjan avatar Aug 28 '24 16:08 reeshabhranjan