Skip to content

Pagination Implementation - #53

Merged
OmarLawaty merged 10 commits into
devfrom
feat/optimizations/pagination
Sep 6, 2026
Merged

OmarLawaty merged 10 commits into
devfrom
feat/optimizations/pagination

Conversation

@OmarLawaty

Copy link
Copy Markdown
Member

No description provided.

@OmarLawaty
OmarLawaty requested a lite review from Copilot September 6, 2026 02:26
@OmarLawaty OmarLawaty self-assigned this Sep 6, 2026
@OmarLawaty OmarLawaty added enhancement New feature or request feature labels Sep 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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/limit and return paginated payloads (services now call paginate(); controllers serialize Paginated(...)).
  • Added RequestContextMiddleware under src/common/middlewares/ and updated AppModule import 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

  • PaginatedDTO initializes limit to 20 by default, which unintentionally changes endpoints that set a different default limit in the service layer (e.g., ProductsService.search uses limit = 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.

Comment thread src/common/pagination/pagination.ts Outdated
Comment thread src/common/pagination/pagination.dto.ts
Comment thread src/common/pagination/pagination.ts Outdated
@OmarLawaty
OmarLawaty merged commit ee8d617 into dev Sep 6, 2026
2 checks passed
@OmarLawaty
OmarLawaty deleted the feat/optimizations/pagination branch September 6, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants