@Override() decorator allows you to replace or extend the default behavior of generated CRUD routes with your own custom logic.
Basic usage
Use the@Override() decorator on a controller method to replace a generated route:
The @Override() decorator
BaseRouteName
The name of the route to override. If omitted, the method name (with ‘Base’ suffix) is used.
Available route names
getManyBasegetOneBasecreateOneBasecreateManyBaseupdateOneBasereplaceOneBasedeleteOneBaserecoverOneBase
Calling the base implementation
To call the original generated route handler, usethis.base:
You must implement the
base getter that returns this to access base route implementations.Using @ParsedRequest()
The@ParsedRequest() decorator provides a CrudRequest object with parsed query parameters:
Common override patterns
Add logging
Add authorization
Modify query parameters
Transform response
Custom validation
Complete custom implementation
You can completely replace the base implementation:Override without specifying name
When the method name matches the route name (with ‘Base’ suffix), you can omit the decorator parameter:Adding route decorators
You can add any NestJS decorators to override methods:Working with bulk operations
Accessing request and response
You can inject standard NestJS decorators:Soft delete recovery
Best practices
Always type your parameters
Always type your parameters
Use proper TypeScript types for better IDE support and type safety:
Keep overrides focused
Keep overrides focused
Override methods should have a single responsibility. If you need complex logic, extract it to service methods:
Document your overrides
Document your overrides
Add JSDoc comments to explain why you’re overriding:
Test your overrides
Test your overrides
Override methods should be covered by unit and integration tests: