Skip to content

Add helper for paginating any Prisma query using a cursor derived from a configurable sort field #202

Description

@Chucks1093

Summary

Cursor pagination is implemented independently in each list endpoint with slightly different sort field handling. A generic paginateQuery<T>(model, where, orderBy, cursorField, limit, cursor?) helper should centralise the pattern and guarantee consistent cursor behaviour across all list endpoints.

Scope

  • Add paginateQuery accepting a Prisma model delegate, where clause, orderBy, cursor field name, limit, and optional decoded cursor value
  • Returns { items: T[], nextCursor: string | null, hasMore: boolean }
  • Encode the cursor as base64 of JSON.stringify({ field, value }) for opacity
  • Add unit tests: first page with no cursor, subsequent page using returned cursor, last page returns hasMore: false and nextCursor: null
  • Replace inline pagination logic in at least two existing list endpoints with the helper

Acceptance Criteria

  • First page returned correctly with no cursor
  • Subsequent page uses returned cursor correctly
  • Last page returns hasMore: false and nextCursor: null
  • Cursor is opaque base64 string
  • At least two existing endpoints use the helper

ETA: 12 hours


Coordinate on Telegram

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions