Files
main.tsmain
What you'll learn
- Register one ValidationPipe for the application and choose whitelist, forbidNonWhitelisted and transform deliberately
- Derive an update DTO from a create DTO with PartialType so validators are written once
- Validate a body array and parse a comma-separated query list with ParseArrayPipe
Press Run tests to start the app. Its log appears here.Graded endpoints
A valid body passes the global pipe
Every failed decorator reports its message, and the request never reaches the handler
forbidNonWhitelisted refuses a property no decorator declares, naming it
PartialType made every property optional, so a body with only age passes, and transform turned the :id into a number the service can compare
The derived DTO kept the create DTO's validators: age must still be an integer
ParseArrayPipe validated each item as a CreateCatDto
An item missing its age fails the item validation, so nothing is created
The comma-separated list arrived as numbers
ParseArrayPipe names the bad element
The :id parameter is a number, so the strict comparison in the service finds the cat
Three cats, Tom updated