-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
feature/apiNew feature or requestNew feature or request
Milestone
Description
[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: TypeApiPaginatedResponseDto: DTOPaginationParams: Type- Modify
response.interceptor.tsto supportPaginatedControllerResponse
[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 [...]
}Metadata
Metadata
Assignees
Labels
feature/apiNew feature or requestNew feature or request
Type
Projects
Status
Done