- Reviewed existing donation + confirm flow and campaign stats implementation.
- Reviewed current Prisma schema and confirmed multiplier/matched-fund models exist.
- Multiplier model present (MultiplierType, caps, date windows, milestoneId).
- MatchedFund model present (donationId, campaignId, multiplierId, amounts).
- Ensure schema indexes & relations align with cap/stat queries.
- MultiplierService present with validation + precedence evaluation.
- Tighten evaluation logic to use DB filtering (instead of JS fallback) and add milestone/date window correctness.
- Add unit tests for precedence/tie-break and validation.
- DonationService applies multipliers at confirmation and creates MatchedFund rows.
- Replace JS Number arithmetic with Decimal arithmetic + deterministic rounding.
- Enforce perDonationCap then remaining matchCap consumption with concurrency-safe cap consumption (row-lock or atomic update strategy).
- Store and return matched summary deterministically.
- Keep Campaign.currentAmount donor-only (existing behavior) and document.
- Add controller endpoints for campaign multiplier CRUD.
- Add routes and request validation (zod) for multiplier create/update.
- Enforce authorization: campaign owner or Role.ADMIN for CRUD; finance/admin only for matched-fund reconciliation.
- Ensure public list is allowed but management restricted.
- Update CampaignService.getCampaignStats() to include:
- totalDonated
- totalMatched
- combinedRaised
- matchBreakdown grouped by multiplierId (and matcher)
- Update controller and route response schemas.
- Unit tests:
- MultiplierService validation
- evaluation precedence/tie-break
- rounding rules
- Integration tests:
- donation confirmation creates MatchedFund within caps
- partial match when matchCap insufficient
- multiplier disabled/expired ignored
- Concurrency test:
- concurrent donations never exceed matchCap
- Update docs/API.md with multiplier endpoints + stats fields.
- Add migration notes, rounding method, math definitions.
- Add reconciliation/export guidance.
- Create Prisma migration (after verifying schema changes are committed).
- Add feature flag FEATURE_MULTIPLIER gating multiplier application + endpoints.
- Staged rollout guidance (staging -> limited -> production) and rollback path.