Skip to content

feat(indexer): add event statistics endpoint with type breakdown#208

Merged
therealjhay merged 2 commits into
Betta-Pay:mainfrom
OTimileyin:feat/event-stats-endpoint
Jun 30, 2026
Merged

feat(indexer): add event statistics endpoint with type breakdown#208
therealjhay merged 2 commits into
Betta-Pay:mainfrom
OTimileyin:feat/event-stats-endpoint

Conversation

@OTimileyin

Copy link
Copy Markdown
Contributor

Closes #79

Summary

Adds GET /api/events/stats endpoint to the indexer service for retrieving aggregate event counts by type within a configurable time window.

Endpoint

GET /api/events/stats?from=2025-01-01T00:00:00Z&to=2025-06-01T00:00:00Z

Requires x-service-token header (inter-service auth).

Response

{
  "total": 42,
  "byType": {
    "PaymentCompleted": 30,
    "SettlementTriggered": 12
  },
  "timeRange": {
    "from": "2025-01-01T00:00:00.000Z",
    "to": "2025-06-01T00:00:00.000Z"
  }
}
  • from / to — optional ISO-8601 dates; to defaults to now, omitted from returns all events up to to
  • Invalid or inverted dates → 400 VALIDATION_ERROR
  • Missing auth → 401

Implementation notes

  • Uses existing DateRangeQuery Zod schema from @bettapay/validation for input validation
  • Aggregates via prisma.indexedEvent.groupBy({ by: ['type'], _count: true }) with indexedAt range filter
  • Maps Prisma's [{ type, _count }] output into a flat Record<string, number> and sums total server-side

Verification

  • pnpm --filter indexer type-check — zero new type errors
  • pnpm --filter indexer test — 3 new tests pass (auth rejection, invalid date 400, inverted range 400)
  • Pre-existing failures limited to Redis-dependent rate-limit tests (unrelated)

@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@OTimileyin Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@therealjhay therealjhay merged commit 0699a64 into Betta-Pay:main Jun 30, 2026
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.

Add event count by type endpoint

2 participants