Skip to Content

@ApiFunction

Factory decorator that selects the appropriate CRUD decorator (create, update, delete, get, getList, getMany) based on type. Use it when you want to wrap a repository-facing method without manually importing each specialized decorator.

Signature

@ApiFunction<E extends IApiBaseEntity, R>(options: TApiFunctionProperties<E>)

Options

OptionTypeDescription
entitynew () => EEntity constructor used to instantiate temporary instances for metadata generation.
typeEApiFunctionTypeTarget CRUD operation (CREATE, UPDATE, DELETE, GET, GET_LIST, GET_MANY).
relationsFindOptionsRelations<E>Optional relation map forwarded to the GET_LIST executor for eager loading.

Behavior

  • Wraps the original method, replacing it with the result of the specialized decorator.
  • Provides the service instance (this) to the generated descriptor so repository access and subscribers behave consistently.
  • Throws a descriptive error if the type is not supported.

Example

export class PostService { constructor(public repository: Repository<PostEntity>) {} @ApiFunction<PostEntity>({ entity: PostEntity, type: EApiFunctionType.UPDATE, }) async updatePost(criteria: TApiFunctionUpdateCriteria<PostEntity>, dto: TApiFunctionUpdateProperties<PostEntity>) { // Implementation replaced by the decorator } }
Last updated on