Skip to main content
The CrudOptions interface defines all available configuration options for the @Crud() decorator.

Interface definition

Model options

ModelOptions
required
Defines the entity model for this controller.
any
required
The entity class that this controller manages.

DTO options

DtoOptions
Custom Data Transfer Objects for request validation.
any
DTO class for create operations (POST).
any
DTO class for update operations (PATCH).
any
DTO class for replace operations (PUT).

Example

When DTOs are not specified, the entity class is used with validation groups CRUD-CREATE and CRUD-UPDATE.

Serialize options

SerializeOptions
Response transformation configuration for each route type.
Type<any> | false
Response DTO for the get many route.
Type<any> | false
Response DTO for the get one route.
Type<any> | false
Response DTO for the create one route.
Type<any> | false
Response DTO for the create many route.
Type<any> | false
Response DTO for the update route.
Type<any> | false
Response DTO for the replace route.
Type<any> | false
Response DTO for the delete route.
Type<any> | false
Response DTO for the recover route.

Example

GetCompanyResponseDto

Query options

QueryOptions
Configuration for query behavior, filtering, pagination, and joins.

Allow and exclude fields

string[]
Whitelist of fields that can be used in queries (filter, sort, select).
string[]
Blacklist of fields that cannot be used in queries.
string[]
Fields that are always returned in responses, even if not requested.

Filtering

QueryFilterOption
Server-side filters that are always applied to queries.

Sorting

QuerySort[]
Default sort order for queries.

Pagination

number
Default number of entities to return per page.
number
Maximum number of entities that can be requested per page.
boolean
When true, all responses are paginated. When false, only paginate when limit is specified.

Soft delete

boolean
Enable soft delete support. Deleted entities are filtered out by default.

Caching

number | false
Cache duration in milliseconds, or false to disable caching.

Join options

JoinOptions
Configuration for entity relations.

Join example

  • Nested joins: Use dot notation like 'company.projects' to join through relations
  • Eager loading: Set eager: true to always include the relation
  • Field filtering: Use allow and exclude to control which relation fields can be queried
  • Custom aliases: Provide an alias for use in query parameters
  • Required joins: Set required: true for INNER JOIN behavior

Params options

ParamsOptions
Configuration for URL path parameters.

Example: Nested routes

This creates routes like:
  • GET /companies/1/users
  • GET /companies/1/users/5
  • POST /companies/1/users

Example: UUID primary key

Example: Disabled parameter

Validation options

ValidationPipeOptions | false
NestJS ValidationPipe configuration, or false to disable validation.
Set to false to disable automatic validation:
See Validation for more details.

Routes factory

typeof CrudRoutesFactory
Custom routes factory class for advanced customization.
This is an advanced option for creating custom route generation logic. Most users should not need to modify this.

Complete example