Skip to content

Normalize pagination metadata across all list endpoints into a shared envelope #301

Description

@therealjhay

Current behavior:
The GET /api/settlements endpoint returns paginated data but the envelope structure differs from other list endpoints. There is no shared PaginatedResponse<T> type.

Expected behavior:
Define a generic PaginatedResponse<T> in @bettapay/types:

interface PaginationMeta {
  page: number;
  limit: number;
  total: number;
  totalPages: number;
  hasNext: boolean;
  hasPrev: boolean;
}
interface PaginatedResponse<T> { data: T[]; pagination: PaginationMeta; }

Refactor the settlement listing (gateway + settlement-engine), event listing (indexer), and any other list endpoints to use this envelope. Update corresponding Zod schemas.

Files to modify:

  • shared/types/index.ts — add types
  • shared/validation/schemas.ts — update response schemas
  • services/api-gateway/src/index.ts, services/settlement-engine/src/index.ts, services/indexer/src/index.ts

Edge cases:

  • totalPages must be 0 when total is 0 (not 1).
  • hasNext must be false when on last page or total is 0.
  • When limit exceeds a maximum (e.g., 100), return 422.

Test requirements:

  1. Page 1 with 5 items, 13 total — verify page=1, totalPages=3, hasNext=true, hasPrev=false.
  2. Page 3 with 5 items — verify hasNext=false, hasPrev=true.
  3. Fetch with limit > 100 — verify 400.

Acceptance criteria:

  • All list endpoints return the identical PaginatedResponse envelope.
  • @bettapay/types exports both types.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions