Repository navigation
Pagination Implementation - #53
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The pagination helper and DTO defaults introduce confirmed correctness issues (sorting being dropped for expression-based ORDER BY and ID type mismatches that can drop items), and DTO default initializers unintentionally override endpoint-specific default limits.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Implements a shared pagination pattern across multiple list/search endpoints (users, products, orders, discounts) by introducing a common pagination helper + DTOs, and updating controllers to serialize paginated responses consistently.
Changes:
- Added
paginate()helper and pagination DTO utilities (PaginatedDTO,Paginated(ItemDto)) to standardize{ data, meta }responses. - Updated admin/user list endpoints to accept
page/limitand return paginated payloads (services now callpaginate(); controllers serializePaginated(...)). - Added
RequestContextMiddlewareundersrc/common/middlewares/and updatedAppModuleimport path.
File summaries
| File | Description |
|---|---|
| src/users/users.service.ts | Returns paginated admin user list via paginate(qb, params). |
| src/users/dtos/admin/admin-search-users.dto.ts | Adds pagination query params by extending PaginatedDTO. |
| src/users/controllers/admin-users.controller.ts | Serializes admin user list as Paginated(AdminUserDTO). |
| src/products/services/products.service.ts | Uses paginate() for admin search branch; manual {data, meta} pagination for user branch. |
| src/products/dtos/user/search-products.dto.ts | Adds pagination query params by extending PaginatedDTO. |
| src/products/dtos/admin/admin-search-products.dto.ts | Adds pagination query params by extending PaginatedDTO. |
| src/products/controllers/products.controller.ts | Serializes product search as Paginated(SearchDTO). |
| src/products/controllers/admin-products.controller.ts | Serializes admin product search as Paginated(AdminProductDTO). |
| src/orders/services/orders.service.ts | Returns paginated order search results via paginate(qb, { page, limit }). |
| src/orders/dtos/admin/admin-search-orders.dto.ts | Adds pagination query params by extending PaginatedDTO. |
| src/orders/controllers/orders.controller.ts | Adds paginated GET /orders with PaginatedDTO query + Paginated(OrderDTO) serialization. |
| src/orders/controllers/admin-orders.controller.ts | Serializes admin orders search as paginated; moves serialization to method level. |
| src/discounts/dtos/admin/admin-search-discounts.dto.ts | Adds pagination query params by extending PaginatedDTO. |
| src/discounts/discounts.service.ts | Returns paginated discount search results via paginate(qb, params). |
| src/discounts/controllers/admin-discounts.controller.ts | Serializes discount search as Paginated(AdminDiscountDTO). |
| src/common/pagination/pagination.ts | New pagination helper that pages by root IDs and returns { data, meta }. |
| src/common/pagination/pagination.dto.ts | New pagination DTOs/meta contract + Paginated(ItemDto) response wrapper. |
| src/common/middlewares/request-context.middleware.ts | New middleware to initialize locale/auth async context and set x-locale header. |
| src/app.module.ts | Updates import path to the new middleware location. |
Review details
Suppressed comments (1)
src/common/pagination/pagination.dto.ts:25
PaginatedDTOinitializeslimitto20by default, which unintentionally changes endpoints that set a different default limit in the service layer (e.g.,ProductsService.searchuseslimit = 8, but the DTO will always supply 20 when omitted). Remove the initializer and let the service/pagination helper default it.
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
@Max(100)
limit?: number = 20;
- Files reviewed: 18/19 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
No description provided.