Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with ValidateIf and ValidateNested #62

Open
reeshabhranjan opened this issue Aug 28, 2024 · 3 comments
Open

Does not work with ValidateIf and ValidateNested #62

reeshabhranjan opened this issue Aug 28, 2024 · 3 comments

Comments

@reeshabhranjan
Copy link

reeshabhranjan commented Aug 28, 2024

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
Copy link
Author

@dmitriy-nz

@dmitriy-nz
Copy link
Owner

Hey, could you provide your ValidationPipe declaration. In ideal will be grate to have playground for reproducing

@reeshabhranjan
Copy link
Author

reeshabhranjan commented Aug 28, 2024

Hey, could you provide your ValidationPipe declaration. In ideal will be grate to have playground for reproducing

@dmitriy-nz this is how my app.module.ts looks like:

	providers: [
		{
			provide: APP_FILTER,
			useClass: PrismaExceptionFilter,
			scope: Scope.REQUEST,
		},
		{
			provide: APP_PIPE,
			useValue: new ValidationPipe({
				transform: true,
			}),
		},
		AppService,
		UserService,
		TwilioService,
		StripeService,
	],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants