@ApiFunctionDelete
Decorates a service method so it loads an entity, runs subscriber hooks, and removes the record through the repository or transaction manager. It reuses @ApiFunctionGet internally to guarantee consistent “not found” errors and guard-friendly behavior.
Signature
@ApiFunctionDelete<E extends IApiBaseEntity>(
properties: IApiFunctionProperties<E>
)Decorated methods gain the shape delete(criteria: TApiFunctionDeleteCriteria<E>, eventManager?: EntityManager): Promise<E>.
Behavior
- Executes
onBeforeDeletesubscribers with the provided criteria. Returning criteria replaces the original input. - Ensures the service has a repository; otherwise throws and notifies error subscribers.
- Lazily decorates a helper
getmethod using@ApiFunctionGetto fetch the entity before deletion, preserving consistent error handling. - Removes the entity via
repository.removeoreventManager.getRepository(entity).remove. - Runs
onAfterDeletesubscribers, allowing them to return a different entity snapshot. - On exceptions, executes
onBeforeErrorDeleteoronAfterErrorDeletesubscribers and rethrowsHttpExceptioninstances, wrapping other errors.
Example
export class PostService {
constructor(public repository: Repository<PostEntity>) {}
@ApiFunctionDelete<PostEntity>({ entity: PostEntity })
async remove(criteria: TApiFunctionDeleteCriteria<PostEntity>) {
return {} as PostEntity;
}
}Related resources
Last updated on