@ApiFunctionGet
Decorates a service method so it fetches a single entity using repository or transactional manager APIs while running subscriber hooks before and after the read. It centralizes “not found” errors so controllers can rely on consistent HTTP semantics.
Signature
@ApiFunctionGet<E extends IApiBaseEntity>(
properties: IApiFunctionProperties<E>
)Decorated methods gain the shape get(properties: TApiFunctionGetProperties<E>, eventManager?: EntityManager): Promise<E>.
Behavior
- Executes
onBeforeGetsubscribers with the incomingFindOneOptions. Returning options overrides the query before execution. - Queries via
repository.findOneoreventManager.getRepository(entity).findOne. - Throws
NotFoundExceptionwith a generated error message if no entity is found. - Runs
onAfterGetsubscribers and allows them to swap the returned entity. - Emits
onBeforeErrorGetandonAfterErrorGethooks for HTTP or unexpected errors.
Example
export class PostService {
constructor(public repository: Repository<PostEntity>) {}
@ApiFunctionGet<PostEntity>({ entity: PostEntity })
async getById(properties: TApiFunctionGetProperties<PostEntity>) {
return {} as PostEntity;
}
}Related resources
Last updated on