Skip to main content

Overview

The @Override decorator is a method decorator that allows you to replace the auto-generated CRUD routes with your own custom implementations. This is useful when you need to add custom business logic, validation, or modify the default behavior of a CRUD operation.

Signature

Parameters

BaseRouteName
The name of the base route to override. If not provided, the decorator infers the route name from the method name by appending Base.Possible values:
  • getManyBase - Override the get many route
  • getOneBase - Override the get one route
  • createOneBase - Override the create one route
  • createManyBase - Override the create many route
  • updateOneBase - Override the update one route
  • replaceOneBase - Override the replace one route
  • deleteOneBase - Override the delete one route
  • recoverOneBase - Override the recover one route

Usage

Implicit Route Name

When you don’t specify a route name, the decorator automatically infers it from your method name:
The method name getMany automatically maps to overriding getManyBase.

Explicit Route Name

You can explicitly specify which route to override:

Adding Business Logic

Modifying Response

Using with Authentication

Complete Integration Test Example

From the source tests:
packages/crud/test/crud.decorator.override.spec.ts:25-56

Implementation Details

The decorator stores metadata about the override:
packages/crud/src/decorators/override.decorator.ts:4-11
If no name is provided, the decorator uses the method name and appends Base to determine which route to override.
When you override a route, you still have access to the base implementation through the base property if you implement the CrudController interface. This allows you to add logic before or after the base implementation.
Overridden methods must have the same route path and HTTP method as the base route they’re replacing. The framework automatically applies the correct routing metadata.

Tips

  1. Use @ParsedRequest() to access the parsed CRUD request with filters, pagination, and joins
  2. Use @ParsedBody() to access the validated and transformed request body
  3. Implement CrudController<T> to get access to the base methods via this.base
  4. Validation still applies - DTOs are validated even in overridden routes
  5. Swagger documentation is automatically generated for overridden routes

See Also