Files
main.tsmain
What you'll learn
- Describe a request body with a DTO class and class-validator rules, and read the messages the rules generate
- Enable ValidationPipe once for the whole application, with whitelist stripping unknown fields
- Convert a route parameter with ParseIntPipe and get a 400 for input that is not a number
Press Run tests to start the app. Its log appears here.Graded endpoints
A valid cat is created, and the unknown color field is stripped by whitelist before the handler sees the body
One message per failed rule, in property order, as a 400; the handler never runs
A number where a string is expected and a fraction where an integer is expected: type rules fail too
Only the valid cat was stored; the rejected bodies never reached the service
ParseIntPipe rejects a non-numeric id before the handler runs
The id arrives in the handler as a number