Skip to content

feat: add risk evaluation history endpoint#76

Open
Hallab7 wants to merge 2 commits intoCreditra:mainfrom
Hallab7:feature/risk-evaluation-history-endpoint
Open

feat: add risk evaluation history endpoint#76
Hallab7 wants to merge 2 commits intoCreditra:mainfrom
Hallab7:feature/risk-evaluation-history-endpoint

Conversation

@Hallab7
Copy link

@Hallab7 Hallab7 commented Feb 26, 2026

Implement GET /api/risk/history/:walletAddress endpoint to retrieve
historical risk evaluations for a given wallet address, including risk
scores, credit limits, timestamps, and optional evaluation inputs.

Changes:

  • Add RiskEvaluationRepository with create() and findByWalletAddress()
  • Implement getRiskHistory() service function with wallet validation
  • Add GET /api/risk/history/:walletAddress route with unified response format
  • Update OpenAPI documentation with complete endpoint specification
  • Fix wallet address validation regex (55 chars total, not 56)
  • Add support for future risk engine outputs via flexible inputs field

Features:

  • Returns evaluations ordered by date (newest first)
  • Proper error handling with 400 status for invalid addresses
  • Secure parameterized queries to prevent SQL injection
  • Database connection lifecycle management (connect/end)
  • Risk level calculation (low < 40, medium 40-69, high >= 70)

Testing:

  • 57 new tests across repository, service, and route layers
  • 100% coverage on new code (repository, service function, endpoint)
  • All tests passing

How to test:

Run all new tests

npm test -- src/db/riskEvaluationRepository.test.ts src/test/riskHistoryRoute.test.ts src/test/riskHistoryService.test.ts

Run with coverage report

npm test -- --coverage src/db/riskEvaluationRepository.test.ts src/test/riskHistoryRoute.test.ts src/test/riskHistoryService.test.ts

Files changed:

  • src/db/riskEvaluationRepository.ts (new)
  • src/db/riskEvaluationRepository.test.ts (new)
  • src/services/riskService.ts (enhanced)
  • src/routes/risk.ts (enhanced)
  • src/test/riskHistoryRoute.test.ts (new)
  • src/test/riskHistoryService.test.ts (new)
  • docs/openapi.yaml (updated)
  • src/openapi.yaml (updated)
  • vitest.config.ts (updated coverage config)
  • RISK_HISTORY_IMPLEMENTATION.md (new)

Closes #24

@greatest0fallt1me
Copy link
Contributor

@Hallab7 Can you resolve the conflicts?

@Hallab7
Copy link
Author

Hallab7 commented Feb 27, 2026

@greatest0fallt1me conflict resolved.

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.

Implement risk evaluation history endpoint for a wallet

2 participants