Support #11222
openimplementing sorting filter in all list apis thoughout the admin pannel
Subtasks
Related issues
Updated by Ajit A 4 days ago
- % Done changed from 0 to 90
1. Customer Management Module
Controller:
customer.controller.ts
Added Swagger documentation @ApiQuery decorators for sortBy and sortOrder query parameters on the getAdminCustomers endpoint.
Service:
customer.service.ts
Updated getAdminCustomers() method signature to accept sortBy and sortOrder.
Added dynamic Mongoose sort construction:
Supports composite name sorting (firstName, lastName, and name).
Supports single-field sorting (email, phone, role, walletBalance, createdAt, etc.).
Preserves default fallback sorting by { createdAt: -1 }.
2. Vendor Management Module
DTO:
get-vendors-query.dto.ts
Added optional @IsOptional() @IsString() fields for sortBy and sortOrder.
Controller:
vendor.controller.ts
Added @ApiQuery decorators for sortBy and sortOrder on getAllVendors.
Forwarded sortBy and sortOrder from query params to the vendor service.
Service:
vendor.service.ts
Updated getAllVendors() to dynamically build sort criteria across name, email, phoneNumber, address, and createdAt (defaulting to { createdAt: -1 }).
3. Vendor Invoices / Purchases Module
Controller:
vendor-purchase.controller.ts
Added @ApiQuery decorators and @Query('sortBy'), @Query('sortOrder') parameters on the getAllPurchases endpoint.
Forwarded sort parameters to getAllVendorPurchases().
Service:
vendor.service.ts
Updated getAllVendorPurchases() to dynamically sort database records by invoiceNumber, paymentStatus, totalAmount, paidAmount, dueAmount, and createdAt.
Key Modifications & Features
Customer Management Module (/customer):
File(s):
customer.controller.ts
,
customer.service.ts
Details:
Added Swagger @ApiQuery decorators for sortBy and sortOrder.
Updated getAdminCustomers() service method to accept dynamic sorting parameters.
Implemented composite field sorting (e.g. name maps to firstName, lastName, and name) with a fallback default sort of { createdAt: -1 }.
Vendor Management Module (/vendors):
File(s):
get-vendors-query.dto.ts
,
vendor.controller.ts
,
vendor.service.ts
Details:
Extended GetVendorsQueryDto with optional sortBy and sortOrder validation properties.
Updated getAllVendors() endpoint and service method to dynamically sort Mongoose query results across fields (e.g., name, email, phoneNumber, address, createdAt).
Vendor Invoices / Purchases Module (/vendor-purchases):
File(s):
vendor-purchase.controller.ts
,
vendor.service.ts
Details:
Added @Query('sortBy') and @Query('sortOrder') decorators to getAllPurchases().
Updated getAllVendorPurchases() to dynamically sort records by invoiceNumber, paymentStatus, totalAmount, paidAmount, dueAmount, and createdAt.
Updated by Ajit A 4 days ago
Key Modifications & Features
Users Module (
users.controller.ts
&
users.service.ts
):
Refactored getUsers and getDeletedUsers to use explicit @Query() decorators with Swagger @ApiQuery() metadata (page, limit, search, role, fromDate, toDate, sortBy, sortOrder).
Added Mongoose .collation({ locale: 'en', strength: 2 }) on adminModel.find() for case-insensitive natural sorting on name, email, phone, and role.
Implemented in-memory multi-attribute sorting for combined deleted users (admins + customers).
Advertising Module (
advertising.controller.ts
&
advertising.service.ts
):
Added sortBy and sortOrder query parameters to findAll and findDeleted endpoints.
Applied .collation({ locale: 'en', strength: 2 }) for accurate case-insensitive sorting on text fields.
Banners Module (
banners.controller.ts
&
banners.service.ts
):
Enabled dynamic sortBy and sortOrder handling in findAll and findDeleted methods.
Added case-insensitive collation for banner listing and soft-deleted banner queries.
Custom Designs Module (
custom-design.controller.ts
&
custom-design.service.ts
):
Added dynamic sort field mapping in getAllCustomDesigns for columns: name $\rightarrow$ customer.name, email $\rightarrow$ customer.email, phone $\rightarrow$ customer.phone, orderStatus/status $\rightarrow$ status, createdAt.
Added sortBy and sortOrder support to getDeletedCustomDesigns.
Enforced active records filter isDeleted: { $ne: true }.
🐛 Bug Fixes & Technical Improvements
Fixed TypeScript compilation type errors (TS2367) across service classes by cleaning up strict type comparisons for sortOrder.
Ensured full backward compatibility: default fallback sorts (createdAt: -1 / deletedAt: -1) apply when sortBy is omitted.