feat(wallet): add pagination and filtration for history and admin views#13
Open
SH-AHD wants to merge 1 commit into
Open
feat(wallet): add pagination and filtration for history and admin views#13SH-AHD wants to merge 1 commit into
SH-AHD wants to merge 1 commit into
Conversation
…lookups with input validation
KhaledSayed04
approved these changes
May 5, 2026
KhaledSayed04
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. Just check the minor notes.
| }); | ||
| } | ||
| // Validate maxBalance | ||
| if (maxB !== undefined && maxB !== '' && (isNaN(parseFloat(maxB)) || parseFloat(maxB) < 0)) { |
Collaborator
There was a problem hiding this comment.
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) { |
Collaborator
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
getTransactionHistoryto filter by transaction type (case-insensitive) and date range (startDate, endDate).Updated
getAllWalletsto include optional balance range filters (minBalance, maxBalance) while preventing N+1 queries by pre-fetching the user email.validateWalletFilters: Ensures skip and take are non-negative, minBalance and maxBalance are valid positive numbers, andminBalance <= 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/historyand/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).