Entity Options

Here are your options:

imports?: Array<
    Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference
  >;
providers?: Provider[];
swagger?: boolean;
guards?: Guard[];
decorators?: (() => ClassDecorator)[];
prismaClient: InjectionToken;
entities: CrudGeneratorConfig[];

1. prismaClient (required)

The prismaClient is the injection token of your Prisma Client instance that will be used to interact with your database.

2. entities (required)

The entities option is an array of CrudGeneratorConfig objects, each representing a database model and its configuration. This option allows you to define the entities that should have automatic CRUD functionality and customize how those operations behave.

The CrudGeneratorConfig can take these attributes:

dto?: Type;
guards?: Guard[];
decorators?: (() => ClassDecorator)[];
path: string;
operations: CrudGeneratorOperation[];
prismaConfig: PrismaConfig<P>;
  • dto?: Defines the Data Transfer Object (DTO) for the entity. DTOs are used to specify the shape of data sent or received in requests and responses, ensuring proper validation and structure.

    To make sure properties appear in the schema and metadata, you must use validation decorators (from class-validator) on each property.

Example:

  • guards?: Specifies an array of guards to apply to the entity's routes. Guards control access to routes, often handling authentication or authorization logic

  • decorators?:An array of functions that return class decorators to modify the behavior of the entity. Decorators can be used for adding metadata, logging, validation, or other runtime behaviors.

  • path: Defines the API path for this entity. This path is used to construct endpoint URLs.

  • operations: An array of CRUD operations for the entity, such as GET, LIST, CREATE, UPDATE, DELETE_BY_ID, and METADATA. Each operation can be customized with additional properties like filters, ordering, and query parameters

  • prismaConfig: Configures how Prisma interacts with the database for this entity. Allows you to specify the Prisma model name and fine-tune queries with select to return only specific fields.

  • acl: or Access Control Level, an object contains a set of configurations used to apply specific access rules on the data depending on the request. Consists of:

    • rowAccess: a function that takes the request object and returns an entity filter, this filter will be used on all operations ensuring data authorization is applied to all users

There are many constant parameters for all methods:

  • decorators? : The decorators option allows you to define an array of decorators that will be applied to the routes.

  • guards?: The guards option allows you to specify an array of NestJS guards to apply to the routes Guards are used to enforce authorization, authentication, or other custom validation logic before a request is processed

  • inject?: The inject option allows you to provide dependencies that will be injected into the handler method, enabling access to services or other resources.

  • handler?: The handler option allows you to specify a custom function to handle the request when the route is accessed.

  • validate?: An optional function that takes the request object and returns a boolean, this function is invoked before each operation to check whether the request is valid and allowed to access that resource

Last updated