Skip to content

fix: consolidate credit tier resolution into CreditScoringService and…#108

Open
KingFRANKHOOD wants to merge 1 commit into
StepFi-app:mainfrom
KingFRANKHOOD:fix/consolidate-credit-tier-resolver
Open

fix: consolidate credit tier resolution into CreditScoringService and…#108
KingFRANKHOOD wants to merge 1 commit into
StepFi-app:mainfrom
KingFRANKHOOD:fix/consolidate-credit-tier-resolver

Conversation

@KingFRANKHOOD

Copy link
Copy Markdown

Summary

Removes the duplicate credit tier table in loans.service.ts and establishes CreditScoringService as the single source of truth for tier resolution, interest rates, and credit limits. All values now match the authoritative parameters-contract deployed on Stellar testnet.
Closes #100

Problem

There were two credit tier tables:

  1. CreditScoringService (credit-scoring.service.ts) — proper NestJS service, injected but only used for loan assessment decisions
  2. LoansService.mapScoreToCreditTier() (loans.service.ts:675) — private hardcoded table used by getAvailableCredit, contradicting both the service and the documented protocol parameters

Neither matched the contracts:

Tier API (old) Contracts
Gold 5,000 10,000 / 4%
Silver 3,000 5,000 / 6%
Bronze 1,500 2,500 / 8%
Starter poor 500 1,000 / 10%

A learner could be shown a credit limit the chain would reject.

What Changed

Core fix

  • Deleted mapScoreToCreditTier() from loans.service.ts — no longer exists
  • Wired getAvailableCredit() through CreditScoringService.resolveTier() — both paths now use the same service
  • Added CREDIT_TIERS constant array in credit-scoring.service.ts — one table, one place, named constants matching the parameters-contract
  • Added CreditScoringService.resolveTier(score) method — public, canonical tier resolution

Tier naming reconciliation

  • Changed tier name from poor to starter across all DTOs, services, and consumers to match the contracts
  • BREAKING: API responses now return starter instead of poor for the lowest tier

Contract-aligned values

  • Gold: maxCredit 10,000, interestRate 4% (was 5,000)
  • Silver: maxCredit 5,000, interestRate 6% (was 3,000)
  • Bronze: maxCredit 2,500, interestRate 8% (was 1,500)
  • Starter: maxCredit 1,000, interestRate 10% (was 500)

Consumers updated

  • ReputationService.mapToReputation() now uses CREDIT_TIERS instead of inline if/else
  • ReputationTier type: poor -> starter

Tests

  • 36 credit-scoring tests including contract alignment assertion and boundary scores 90, 89, 75, 74, 60, 59
  • 47 loans tests pass with updated credit limits
  • 11 reputation tests pass with updated tier names and rates

Breaking Changes

StepFi-Web and StepFi-App must update:

  1. Replace poor tier name references with starter in tier-based rendering logic
  2. Update credit limit display: gold 10,000, silver 5,000, bronze 2,500, starter 1,000
  3. Update interest rate display: gold 4%, silver 6%, bronze 8%, starter 10%

Files Changed

File Change
src/modules/credit-scoring/credit-scoring.service.ts Added CREDIT_TIERS, CreditTier, resolveTier()
src/modules/loans/loans.service.ts Deleted mapScoreToCreditTier(), wired to CreditScoringService
src/modules/reputation/reputation.service.ts Uses CREDIT_TIERS instead of inline tier mapping
src/modules/reputation/dto/reputation-response.dto.ts poor -> starter
src/modules/loans/dto/available-credit-response.dto.ts poor -> starter
test/unit/modules/credit-scoring/credit-scoring.service.spec.ts Comprehensive tier + contract alignment tests
test/unit/modules/loans/loans.service.spec.ts Updated mock values and expectations
test/unit/modules/reputation/reputation.service.spec.ts Updated tier names and values
test/e2e/modules/loans/loans.e2e-spec.ts Updated tier name
test/e2e/modules/reputation/reputation.e2e-spec.ts Updated tier name

CI

  • npm run build — 0 errors
  • npm run lint — 0 errors
  • npm test — all 94 unit tests pass

… match contract parameters

- Remove duplicate mapScoreToCreditTier() from loans.service.ts
- Wire getAvailableCredit through CreditScoringService.resolveTier()
- Define CREDIT_TIERS as the single source of truth in credit-scoring.service.ts
- Match authoritative values from parameters-contract (gold: 10000/4%, silver: 5000/6%, bronze: 2500/8%, starter: 1000/10%)
- Reconcile tier naming: 'poor' -> 'starter' across all DTOs, services, and tests
- Add contract-alignment test ensuring CREDIT_TIERS never drifts from parameters-contract
- Add boundary score tests for 90, 89, 75, 74, 60, 59
- Update ReputationService to share CREDIT_TIERS constants

BREAKING CHANGE: API tier name changes from 'poor' to 'starter' in /reputation and
/loans/available-credit responses. Credit limits and interest rates updated to match
deployed contract parameters (gold 10000/4%, silver 5000/6%, bronze 2500/8%,
starter 1000/10%). StepFi-Web and StepFi-App must update tier name references.
@KingFRANKHOOD
KingFRANKHOOD requested a review from EmeditWeb as a code owner July 26, 2026 04:17
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.

fix: remove duplicate credit-tier table from LoansService

1 participant