Add Invoice Comparison Endpoint with Cached Metrics - #998
Merged
Chucks1093 merged 11 commits intoOct 2, 2026
Merged
Chucks1093 merged 11 commits into
Chucks1093 merged 11 commits into
Conversation
- 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)
|
@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! 🚀 |
- 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
… in invoice service
…currency from watchlist select
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
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.
##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.