feat: add GET /api/dashboard/stats endpoint with unit tests#1
feat: add GET /api/dashboard/stats endpoint with unit tests#1mrteeednut007-dotcom wants to merge 1 commit into
Conversation
- Add getDashboardStats query function with 4 concurrent SQL queries for active contracts, completed contracts, total earnings, escrow volume - Add Next.js route handler with 60s revalidation cache and error handling - Fix lib/db.ts to lazily initialize Neon connection (avoids build-time error) - Add unit tests using node:test (no extra dependencies)
2181f60 to
4b941e4
Compare
|
feat: Add GET /api/dashboard/stats endpoint Summary Implements the /api/dashboard/stats endpoint to provide clients and freelancers with aggregated Changes lib/dashboard.ts — getDashboardStats(walletAddress) runs 3 parallel DB queries to compute: Active contracts (status: assigned, in_progress, in_review) Validates wallet presence and Stellar address format (400 on failure) jest.config.js — Jest + ts-jest setup with @/ path alias Testing npm test # 8/8 tests pass API Reference GET /api/dashboard/stats?wallet=G... 200 OK Related Issue |
feat: Add GET /api/dashboard/stats endpoint
Summary
Implements the /api/dashboard/stats endpoint to provide clients and freelancers with aggregated
contract and financial metrics.
Changes
lib/dashboard.ts — getDashboardStats(walletAddress) runs 3 parallel DB queries to compute:
app/api/dashboard/stats/route.ts — GET /api/dashboard/stats?wallet=
tests/dashboard.test.ts — 8 unit tests covering both the query layer and route handler
jest.config.js — Jest + ts-jest setup with @/ path alias
Testing
npm test # 8/8 tests pass
API Reference
GET /api/dashboard/stats?wallet=G...
200 OK
{
"data": {
"activeContracts": 3,
"completedContracts": 7,
"totalEarnings": 1500.50,
"escrowVolume": 300.00
},
"meta": { "generatedAt": "2026-06-23T22:00:00.000Z" }
}
Related Issue
Closes Lumina-eX#124