@ApiFunctionGetList
Provides paginated list retrieval with filtering, sorting, and relation loading using the DTO emitted by the controller. Automatically computes pagination metadata and runs subscriber hooks.
Signature
@ApiFunctionGetList<E extends IApiBaseEntity>(
properties: IApiFunctionProperties<E>
)Decorated methods gain the shape getList(dto: TApiFunctionGetListProperties<E>, eventManager?: EntityManager): Promise<IApiGetListResponseResult<E>>.
Behavior
- Runs
onBeforeGetListsubscribers so they can modify theFindManyOptions(filters, joins, pagination). - Uses
repository.findAndCount(or the transactional repository) to retrieve data and the total count. - Computes
count,totalCount,totalPages, andcurrentPagefor the response DTO. - Executes
onAfterGetListsubscribers, allowing them to reshape items or pagination metadata. - Captures and rethrows HTTP exceptions while notifying
onBeforeErrorGetListoronAfterErrorGetListsubscribers.
Example
export class PostService {
constructor(public repository: Repository<PostEntity>) {}
@ApiFunctionGetList<PostEntity>({ entity: PostEntity })
async getList(properties: TApiFunctionGetListProperties<PostEntity>) {
return { items: [], count: 0, totalCount: 0, totalPages: 0, currentPage: 0 };
}
}Related resources
- Function Decorators overview
TApiFunctionGetListProperties(DTO definition)
Last updated on