Skip to content

Add Invoice Comparison Endpoint with Cached Metrics - #998

Merged
Chucks1093 merged 11 commits into
accesslayerorg:mainfrom
Damilorlar:feature/invoice-comparison-endpoint
Oct 2, 2026
Merged

Chucks1093 merged 11 commits into
accesslayerorg:mainfrom
Damilorlar:feature/invoice-comparison-endpoint

Conversation

@Damilorlar

Copy link
Copy Markdown
Contributor

##closed #947

Description

Implement a comparison endpoint that allows the frontend to fetch and compare up to two invoices in a single request.

The endpoint should return key metrics for each invoice, including amount, rate, maturity, risk rating, seller statistics, and funding progress. Cache responses for 30 seconds per invoice combination to reduce repeated data fetching.

Acceptance Criteria:

Add GET /invoices/compare accepting comma-separated invoice IDs.
Support a maximum of 2 invoice IDs.
Return all required metrics grouped by invoice ID.
Return 400 with a clear error when more than 2 IDs are provided.
Cache responses for 30 seconds using the invoice ID combination as the cache key.
Ensure the response contains all required comparison fields.

- New invoice module with schemas, service, controller, routes
- Accepts comma-separated invoice IDs (max 2) via query param
- Returns side-by-side metrics: amount, rate, maturity, riskRating, sellerStats, fundingProgress
- 30s TTL cache via Cache-Control header
- Returns 400 when more than 2 IDs provided
- Response groups metrics by invoice ID
- Follows existing codebase patterns (zod schemas, async controllers, error handling)
@drips-wave

drips-wave Bot commented Sep 28, 2026

Copy link
Copy Markdown

@Damilorlar Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

- New invoice module with schemas, service, controller, routes
- Accepts comma-separated invoice IDs (max 2) via query param ids
- Returns side-by-side metrics: amount, rate, maturity, riskRating, sellerStats, fundingProgress
- 30s TTL cache via Cache-Control header
- Returns 400 when more than 2 IDs provided
- Response groups metrics by invoice ID
- Fixed duplicate Invoice model in Prisma schema
- Added inverse relation watchlists on Invoice model for InvestorWatchlist relation
- Remove duplicate export default in src/modules/index.ts
- Add select fields to invoice relation in watchlist.service.ts
- Add null coalescing for sellerStats in invoice.service.ts
- Fix sellerWallet -> actor field in sellers.service.ts
The previous commits repurposed the existing Invoice Prisma model, moving it
from invoice.prisma into ownership.prisma and dropping currency/maturityDate.
That broke two unrelated consumers, and the follow-up fix commits mangled
their source instead of reverting the schema.

- restore the Invoice model in invoice.prisma; ownership.prisma no longer
  defines it (no schema change, so no migration required)
- restore watchlist.service.ts and sellers.service.ts, which had lost
  addToWatchlist and been retargeted to a non-existent `actor` field
- mount /invoices once in modules/index.ts; a duplicated router.use() block
  had double-mounted 12 route groups above the query-cost governor, bypassing
  it and the per-group body-size limits
- rebuild the comparison service against the real Invoice model: one findMany
  plus one groupBy for per-seller stats, metrics grouped by invoice ID
- cache responses for 30s in Redis keyed by the sorted ID combination
- add service and controller tests, and document the endpoint

Refs accesslayerorg#947
@Chucks1093
Chucks1093 merged commit b3d8d8d into accesslayerorg:main Oct 2, 2026
1 check passed
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.

Add invoice comparison data endpoint for side-by-side metric retrieval

2 participants