I need to validate a list of emails (array of strings) that are passed via POST
. Using something like validation pipes and class-validator
would be awesome (however in the official docs I only found examples of objects validation through DTOs and validation of primitive types but for GET
requests).
Here is how my method looks like in the controller:
@Post()
async submit(@Body() emails: string[]) {
}
If it's just being passed directly like that, then there's not much you can do besides implement a custom pipe. If you are able to change the payload structure I would suggest it to something like
And use
so that Nest's
ValidationPipe
can read the metadata of the post.