Skip to content

feat(wallet): add pagination and filtration for history and admin views#13

Open
SH-AHD wants to merge 1 commit into
masterfrom
feat/wallet-filters-pagination
Open

feat(wallet): add pagination and filtration for history and admin views#13
SH-AHD wants to merge 1 commit into
masterfrom
feat/wallet-filters-pagination

Conversation

@SH-AHD

@SH-AHD SH-AHD commented May 1, 2026

Copy link
Copy Markdown
Collaborator

This Pull Request enhances the wallet and transaction endpoints by introducing optional filtration and pagination features. It ensures comprehensive validation for filters (balance ranges, date formats, transaction types, and pagination bounds) using custom middlewares, preventing potential errors and ensuring clean downstream logic.

Changes Included:
  1. Enhanced getTransactionHistory to filter by transaction type (case-insensitive) and date range (startDate, endDate).
    Updated getAllWallets to include optional balance range filters (minBalance, maxBalance) while preventing N+1 queries by pre-fetching the user email.
  • Extracted and normalized pagination (skip, take) and optional filters from the request query to pass into the services.
  1. Filter Validation Middlewares:
    validateWalletFilters: Ensures skip and take are non-negative, minBalance and maxBalance are valid positive numbers, and minBalance <= maxBalance.
    validateTransactionFilters: Validates transaction type against valid enum constants, and checks that both startDate and endDate are valid formats and that startDate is before endDate.
  • Attached validations to /api/wallet/history and /api/wallet/admin/all-wallets.

  • Added service-level tests to verify that type and date filters are applied correctly when getting transaction histories.

  • Added service-level tests to ensure balance filters and user email inclusion work perfectly for admin wallet listings.

  • Added comprehensive middleware unit tests for negative tests (e.g., minBalance > maxBalance, invalid transaction type, invalid dates, negative pagination indices) as well as positive, valid pass-through tests.

  • Added new sample test requests, including pagination, balance range filtering, date ranges, and negative test cases to easily manually verify endpoint behavior.

Verification

All 46 tests across the entire testing suite passed successfully (npm test).

@SH-AHD SH-AHD requested a review from KhaledSayed04 May 1, 2026 19:12

@KhaledSayed04 KhaledSayed04 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Just check the minor notes.

});
}
// Validate maxBalance
if (maxB !== undefined && maxB !== '' && (isNaN(parseFloat(maxB)) || parseFloat(maxB) < 0)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

var !== '' check is added for minB & maxB and not for skip & take
while all are supposed to be numerical values.



// 2. Validate take
if (take) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider extracting pagination validation into its own middleware.

Right now skip and take are validated in both validateWalletFilters and validateTransactionFilters with the same logic.

This could be a good opportunity to keep the code DRY and maintain a single source of truth for pagination rules.

A small refactor, like creating a validatePagination middleware, would let you reuse it across any route that needs pagination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants