#Query param validation against an enum
16 messages · Page 1 of 1 (latest)
If you define a DTO for your query params, and use it like this:
@Params() params: ParamsDTO
You can use @IsEnum form class-validator
Otherwise you can create a custom pipe that would check it for you.
Aha, good tip, thanks I'll try that :)
Where is @Params() from? did you mean @Query()?
This is what I've got, but the validator doesn't seem to be doing much
You have the ValidationPipe bound, right?
No I don't have a ValidationPipe. I had one before, but I didn't specifically bind it besides using a decorator, and I was declaring the parameter directly in the getCmaData() params rather than use a InitialDataParamsDto
If you don't use the ValidationPipe then the class-validator decorators aren't gonna help you
Hmm I'll have to look into its usage, thanks :)
I just realized you were talking about query params. In that case you need the @Query decorator
Yeah :P I presumed it worked the same
Ok nice I just had to add @UsePipes(new ValidationPipe()) at the top of the file:
Works, thank you!
!close