Skip to Content

@ApiRouteSubscriber

Registers a class as a route-level subscriber for a specific entity. Subscribers intercept controller lifecycles (before, after, error) whenever an observable controller executes CRUD routes.

Signature

@ApiRouteSubscriber<E extends IApiBaseEntity>({ entity, priority?, }: IApiRouteSubscriberProperties<E>)

Options

OptionDescription
entityEntity that the subscriber observes.
priorityExecution order (higher runs first). Defaults to 0.

Usage steps

  1. Add @ApiControllerObservable() to the controller that should emit events.
  2. Extend ApiRouteSubscriberBase<E> and implement lifecycle hooks such as onBeforeCreate, onBeforePartialUpdate, onAfterGetList, or onAfterErrorDelete.
  3. Decorate the subscriber class with @ApiRouteSubscriber.

Example

@Injectable() @ApiRouteSubscriber<PostEntity>({ entity: PostEntity, priority: 10 }) export class PostAuditSubscriber extends ApiRouteSubscriberBase<PostEntity> { async onAfterCreate(context: TApiSubscriberRouteAfterCreateContext<PostEntity>) { this.logger.log("Post created", context.result); return context.result; } }
Last updated on