[1] Feature Description
Resources with array return types should allow for pagination.
The pagination should happen using query parameters by the requester:
{url}?page={num}&limit={num}
The server should then respond with the data in the following format:
{
"status": 200,
"message": "Success",
"data": [],
"meta": {
"page": {num},
"perPage": {num},
"totalItems": {num},
"totalPages": {num}
}
}
[2] Implementation
This feature is achieved by implementing two decorators:
@Paginated(): Route-Level decorator to add documentation and metadata
@Pagination(): Param-Level decorator to extract and validate types from the request and return them in a unified format
Additionally, some utility functions and types are implemented to modify the returned data with the correct meta keyword:
PaginatedControllerResponse: Type
ApiPaginatedResponseDto: DTO
PaginationParams: Type
- Modify
response.interceptor.ts to support PaginatedControllerResponse
[3] Example
import {
Pagination,
PaginationParams,
} from "src/common/decorators/pagination.decorator";
import { PaginatedControllerResponse } from "src/typings";
import { ApiPaginatedResponseDto } from "src/common/decorators/api-response.decorator";
@Get("/")
@Paginated()
@ApiPaginatedResponseDto(ApplicationDto, { description: "Success" })
async getPaginatedURL(
@Pagination() pagination: PaginationParams,
): PaginatedControllerResponse {
return [...]
}
[1] Feature Description
Resources with array return types should allow for pagination.
The pagination should happen using query parameters by the requester:
{url}?page={num}&limit={num}The server should then respond with the data in the following format:
{ "status": 200, "message": "Success", "data": [], "meta": { "page": {num}, "perPage": {num}, "totalItems": {num}, "totalPages": {num} } }[2] Implementation
This feature is achieved by implementing two decorators:
@Paginated(): Route-Level decorator to add documentation and metadata@Pagination(): Param-Level decorator to extract and validate types from the request and return them in a unified formatAdditionally, some utility functions and types are implemented to modify the returned data with the correct
metakeyword:PaginatedControllerResponse: TypeApiPaginatedResponseDto: DTOPaginationParams: Typeresponse.interceptor.tsto supportPaginatedControllerResponse[3] Example