feat(api): add shared pagination helper and creator sort parser#23
Merged
Conversation
|
@Gbangbolaoluwagbemiga 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements shared pagination helpers and a creator-specific sort option parser to ensure consistent API responses and safe, validated sorting for the creator listing endpoint.
Key Changes
Shared Pagination Infrastructure:
Added
PaginationMetadata
and
PaginatedResponse
interfaces to
src/utils/api-response.utils.ts
.
Implemented
sendPaginatedSuccess
helper for standardized paginated responses across the API.
Creator Sort Option Parser:
Created
src/modules/creator/creator.utils.ts
with a
parseCreatorSortOptions
function.
Validates allowed sort fields (handle, displayName, createdAt) and directions (asc, desc).
Falls back to safe defaults (createdAt: desc) for invalid or missing inputs.
New Creator Module:
Service: Implemented paginated Prisma queries with dynamic ordering.
Controller: Added logic to parse query parameters and return formatted paginated responses.
Routes: Exposed GET /api/v1/creators.
Configuration:
Registered the creator router in the main API router (
src/modules/index.ts
).
Updated
tsconfig.json
to include es2017 and dom libraries to resolve type errors for Array.includes and console.
Verification
Verified that the sort parser correctly rejects unsupported keys.
Confirmed pagination metadata (total pages, next/prev flags) is calculated accurately.
Ensured the response shape matches the requirements for both data and metadata inclusion.
Issues Addressed
Closes #18
Closes #20
Closes #11
Closes #22