feat(api): paginate & filter GET /loans and GET /groups (closes #3) - #16
Open
Vyacheslav-Tomashevskiy wants to merge 2 commits into
Open
Conversation
…inance#3) Both endpoints returned all rows unbounded. Add offset pagination with a { data, meta } envelope, a reusable PaginationQueryDto (page>=1 default 1, limit 1..100 default 20; a limit >100 is rejected 400 by the global ValidationPipe), plus sortBy(amount|requestedAt)+order for loans while keeping the existing groupId/status filters. Count and page fetched in one prisma.$transaction; Swagger @apiquery added for every param. Service-layer unit tests + DTO validation tests (10 tests, jest).
# Conflicts: # jest.config.js # src/modules/groups/groups.controller.ts # src/modules/loans/loans.controller.ts
Vyacheslav-Tomashevskiy
force-pushed
the
feat/pagination-loans-groups-3
branch
from
July 24, 2026 16:20
912e5bf to
2e777aa
Compare
Author
|
Rebased onto latest |
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.
Closes #3.
Problem
GET /api/loansandGET /api/groupsreturned all records with no bound — slow responses and heavy memory use once a group has hundreds of contributions or there are thousands of loans.Changes
PaginationQueryDto(src/common/dto/pagination-query.dto.ts):page(>=1, default 1) andlimit(1-100, default 20). Built on the existing globalValidationPipe({ transform: true }), so?page=&limit=strings are coerced to numbers and alimit > 100is rejected with 400 automatically (@Max(100)).paginate()helper returns the standard envelope:{ "data": [...], "meta": { "page": 1, "limit": 20, "total": 143, "totalPages": 8 } }.FindLoansQueryDto extends PaginationQueryDto): pagination +sortBy=amount|requestedAt&order=asc|desc(defaultsrequestedAt desc, preserving current behaviour), keeping the existinggroupId/statusfilters.sortBy/orderare whitelisted with@IsInso no arbitrary field reaches Prisma'sorderBy.findAll(); on-chain balance enrichment now runs only over the current page, not the whole table.prisma.$transaction([...]).@ApiQueryadded for every new param on both controllers.Tests
Added a jest setup (repo had none) and 10 unit tests, all green (
npx jest):pagination-query.dto.spec.ts— numeric coercion,limit > 100rejected,< 1rejected, non-integer rejected, envelope math.loans.service.spec.ts— defaults,skip/take/where/orderByderivation,totalPages 0on empty.groups.service.spec.ts— pagination + per-page balance enrichment.Acceptance criteria
metaobject@ApiQueryfor all params)Scope kept tight: no unrelated changes. The 3 pre-existing
tscerrors (stellar.service.ts,notifications.service.ts) are onmainalready and untouched here; the added files type-check clean.