Exercício prático · NestJS

Practice lab: Trace the rejected request

do caderno de estudos · atualizado em 2 de outubro de 2026
Para quem vai encarar entrevista de NestJS2 min

Tente resolver a tarefa antes de consultar os critérios. Compare o resultado e explique o que mudou no seu raciocínio.

Tarefa e critérios de verificação

Task, 15 minutes: design a POST /orders endpoint with an authentication guard, a configured ValidationPipe, and a service injected into the controller. The body contains an integer quantity greater than zero. Trace four cases before testing locally: missing credentials, an authenticated request with quantity 0, an authenticated request with quantity 2, and a valid request whose service throws an uncaught application exception. Write down the components reached and whether the service runs in each case.

Check your work:

  • A request without credentials is rejected by the authentication guard. The service is not called.
  • An authenticated request with quantity 0 fails validation with a client error. The service is not called.
  • An authenticated request with quantity 2 reaches the service and returns the documented creation response.
  • If the service throws an uncaught application exception, the applicable filter shapes the error response. The success response path does not run.

Follow-up: a valid user submits another account's order id. Explain where object-level authorization belongs and why a DTO alone cannot enforce it.

No app, a tarefa fica visível e você pode revelar os critérios depois da tentativa. Use as notas para registrar sua solução.

Praticar este exercício no app