The ModelOptions interface specifies the entity/model class that the CRUD controller will operate on. This is the only required option when configuring a CRUD controller.
The entity class that represents your data model.This should be a TypeORM entity, Mongoose model, or any other ORM entity class that your service layer can work with.
import { Controller } from '@nestjs/common';import { Crud } from '@nestjsx/crud';import { User } from './user.entity';import { UsersService } from './users.service';@Crud({ model: { type: User, // Reference to the entity class }, query: { exclude: ['password'], // Don't expose password field },})@Controller('users')export class UsersController { constructor(public service: UsersService) {}}
The model.type property is the only required field in the entire CrudOptions configuration. All other options have sensible defaults.
Make sure the entity class is properly registered in your ORM module (e.g., TypeOrmModule.forFeature([User]) for TypeORM) before using it in a CRUD controller.
Show Why is type 'any'?
The type property is typed as any to provide flexibility and work with different ORM libraries (TypeORM, Mongoose, Sequelize, etc.). In practice, you’ll pass a specific entity class: