nestjs-paginator
A package to make pagination with NestJS, TypeORM, and Express as simple as possible.
The paginator function returns a class that can be serialized by class-transformer and conforms to JSON:API
Install
npm install nestjs-paginator
Usage
Example example
The following code exposes a route that can be utilized like so:
Endpoint
http://localhost:3000/cat/all?sortBy=color&orderBy=DESC&limit=10&page=2
Result
Code
;;;;
Config
/** * Required: true (must have a minimum of one column) * Type: keyof CatEntity * Description: These are the columns that are valid to be sorted by. */ sortableColumns: , /** * Required: false * Type: number * Default: 100 * Description: The maximum amount of entities to return per page. */ maxLimit: 20, /** * Required: false * Type: keyof CatEntity * Default: sortableColumns[0] * Description: The column which to sort by default. */ defaultSortBy: 'age', /** * Required: false * Type: 'ASC' | 'DESC' * Default: 'ASC' * Description: The order to display the sorted entities. */ defaultOrderBy: 'ASC' | 'DESC', /** * Required: false * Type: number * Default: 20 */ defaultLimit: 50, /** * Required: false * Type: TypeORM find options * Default: None * https://typeorm.io/#/find-optionsfind-options.md */ where: }