Skip to content

feat: add GET /api/dashboard/stats endpoint with unit tests#1

Open
mrteeednut007-dotcom wants to merge 1 commit into
Dayz-tech-co:mainfrom
mrteeednut007-dotcom:feature/dashboard-stats-api
Open

feat: add GET /api/dashboard/stats endpoint with unit tests#1
mrteeednut007-dotcom wants to merge 1 commit into
Dayz-tech-co:mainfrom
mrteeednut007-dotcom:feature/dashboard-stats-api

Conversation

@mrteeednut007-dotcom

Copy link
Copy Markdown

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:

    • Active contracts (status: assigned, in_progress, in_review)
    • Completed contracts
    • Total earnings (sum of confirmed release escrow transactions to the user's wallet)
    • Escrow volume (confirmed deposits minus releases/refunds on active jobs)
  • app/api/dashboard/stats/route.ts — GET /api/dashboard/stats?wallet=

    • Validates wallet presence and Stellar address format (400 on failure)
    • 60s ISR revalidation + Cache-Control: s-maxage=60, stale-while-revalidate=30
    • Returns { data: DashboardStats, meta: { generatedAt } }
    • Graceful 500 with server-side error logging on query failure
  • 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

- 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)
@mrteeednut007-dotcom mrteeednut007-dotcom force-pushed the feature/dashboard-stats-api branch from 2181f60 to 4b941e4 Compare June 24, 2026 06:58
@mrteeednut007-dotcom

Copy link
Copy Markdown
Author

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:

Active contracts (status: assigned, in_progress, in_review)
Completed contracts
Total earnings (sum of confirmed release escrow transactions to the user's wallet)
Escrow volume (confirmed deposits minus releases/refunds on active jobs)
app/api/dashboard/stats/route.ts — GET /api/dashboard/stats?wallet=

Validates wallet presence and Stellar address format (400 on failure)
60s ISR revalidation + Cache-Control: s-maxage=60, stale-while-revalidate=30
Returns { data: DashboardStats, meta: { generatedAt } }
Graceful 500 with server-side error logging on query failure
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

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.

[Feature]: Dashboard Analytics API

1 participant