Sikau

NestJS · Day 10 · about 45 min

Project: Validated orders

DTOs, pipes, exceptions and a guard together.

Everything from this unit

Write the orders controller: validated input, typed ids, meaningful errors, and a guard for the kitchen-only status change.

Test the unhappy paths

An orders API is only trustworthy if it fails well. Before calling the project done, send the requests a careless or hostile client might: an empty items list, a quantity of zero, a dish id that doesn't exist, a status change without the kitchen header, and an id like abc in the URL.

Each should fail with a precise status: 400 for bad shapes and ids, 404 for unknown orders or dishes, 403 for the wrong role. If any of them returns 500 or, worse, succeeds, a rule is missing from a DTO, pipe, guard or service. Fix it in the layer that owns that rule.

The rest of this lesson

  • Map the request to the right layerexplain
  • Never trust totals from the clientexplain
  • Which tool for which requirement?match
  • Nested validationpredict
  • OrdersControllerchallenge
  • Badge quizquiz
  • Unit 2 complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 15 lessons of NestJS