Skip to content

feat: add pagination support to GET /api/orders#56

Open
srija-pixel wants to merge 1 commit intofuzziecoder:mainfrom
srija-pixel:ci/backend-workflow
Open

feat: add pagination support to GET /api/orders#56
srija-pixel wants to merge 1 commit intofuzziecoder:mainfrom
srija-pixel:ci/backend-workflow

Conversation

@srija-pixel
Copy link
Contributor

@srija-pixel srija-pixel commented Feb 27, 2026

Adds pagination support to GET /api/orders.

Previously, the endpoint returned the full dataset without paging.
This update introduces limit/offset pagination with metadata.

Changes Made

Added limit and offset query parameters
Default pagination: limit = 10, offset = 0
Response now includes meta object:
total
limit
offset
hasMore

Added validation for invalid pagination parameters

Returns 400 Bad Request for malformed limit/offset values

Summary by CodeRabbit

  • New Features
    • Orders API now supports paginated retrieval with customizable limit and offset parameters
    • Response includes metadata (total count, limit, offset, and pagination indicator) for efficient data handling

@vercel
Copy link

vercel bot commented Feb 27, 2026

@srija-pixel is attempting to deploy a commit to the Revon Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

The GET /api/orders endpoint has been refactored to implement pagination. The single-order retrieval logic was replaced with multi-parameter filtering (spotId, userId) combined with limit and offset query parameters. Results are validated, sliced, and returned with pagination metadata.

Changes

Cohort / File(s) Summary
Pagination Implementation
backend/server.js
Modified GET /api/orders endpoint to replace single-order retrieval with paginated results. Added limit and offset query parameters with validation (limit must be positive integer, offset non-negative). Returns paginated data array with meta object containing total count, limit, offset, and hasMore flag. Maintains existing spotId and userId filtering.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related issues

Possibly related PRs

  • feat: add GET /api/orders/:id endpoint #34 — Implements a separate GET /api/orders/:id endpoint for single-order retrieval by ID, which relates to this PR's removal of single-order-lookup logic in favor of the paginated approach.

Suggested labels

apertre3.0

Poem

🐰 A hop through time, pagination flows,
Limit and offset, where data goes,
Meta objects dance with hasMore's cheer,
Orders paginated, crystal clear! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: adding pagination support to the GET /api/orders endpoint, which is the primary modification described in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/server.js`:
- Around line 131-138: The code currently calls database.getOrders without
pagination and then slices the full result in server.js, which forces a full
fetch and mapping; update database.getOrders (in backend/db.js) to accept limit
and offset, perform a COUNT(*) query to compute total, run the paged SELECT with
LIMIT ? OFFSET ? to fetch only the requested orders, then fetch/map items only
for the paged order IDs; change the server call (database.getOrders) to pass
limit and offset and consume the new return shape (e.g., { total, orders }) so
server.js uses the DB-provided total and paged orders directly.
- Around line 123-126: The offset parsing currently coerces empty or
whitespace-only values to 0 because it calls Number(offsetParam); update the
validation in the block that reads offsetParam (the code that sets offset =
Number(offsetParam) and calls sendJson) to first reject empty or whitespace-only
strings by checking something like if (typeof offsetParam === 'string' &&
offsetParam.trim() === '') then call sendJson(res, 400, { error: 'Invalid offset
parameter' }) before converting to Number; keep the existing integer and
non-negative checks for offset after conversion.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 76a56ab and 811f06a.

📒 Files selected for processing (1)
  • backend/server.js

Comment on lines +123 to +126
if (offsetParam !== null) {
offset = Number(offsetParam);
if (!Number.isInteger(offset) || offset < 0) {
sendJson(res, 400, { error: 'Invalid offset parameter' });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Reject empty/whitespace offset as malformed.

Line 124 uses Number(offsetParam), so ?offset= and ?offset= are coerced to 0 and currently pass. That conflicts with the “malformed values return 400” behavior.

Suggested fix
   if (offsetParam !== null) {
-    offset = Number(offsetParam);
-    if (!Number.isInteger(offset) || offset < 0) {
+    if (!/^\d+$/.test(offsetParam)) {
+      sendJson(res, 400, { error: 'Invalid offset parameter' });
+      return;
+    }
+    offset = Number(offsetParam);
+    if (!Number.isInteger(offset) || offset < 0) {
       sendJson(res, 400, { error: 'Invalid offset parameter' });
       return;
     }
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (offsetParam !== null) {
offset = Number(offsetParam);
if (!Number.isInteger(offset) || offset < 0) {
sendJson(res, 400, { error: 'Invalid offset parameter' });
if (offsetParam !== null) {
if (!/^\d+$/.test(offsetParam)) {
sendJson(res, 400, { error: 'Invalid offset parameter' });
return;
}
offset = Number(offsetParam);
if (!Number.isInteger(offset) || offset < 0) {
sendJson(res, 400, { error: 'Invalid offset parameter' });
return;
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/server.js` around lines 123 - 126, The offset parsing currently
coerces empty or whitespace-only values to 0 because it calls
Number(offsetParam); update the validation in the block that reads offsetParam
(the code that sets offset = Number(offsetParam) and calls sendJson) to first
reject empty or whitespace-only strings by checking something like if (typeof
offsetParam === 'string' && offsetParam.trim() === '') then call sendJson(res,
400, { error: 'Invalid offset parameter' }) before converting to Number; keep
the existing integer and non-negative checks for offset after conversion.

Comment on lines +131 to +138
// Get full filtered result first
const allOrders = database.getOrders({ spotId, userId });

if (!order) {
sendJson(res, 404, { error: `Order not found: ${orderId}` });
return;
}
const total = allOrders.length;

// Apply pagination
const paginatedOrders = allOrders.slice(offset, offset + limit);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Move pagination to the database layer to avoid full fetches.

Line 132 fetches all filtered orders, then Line 137 slices in memory. Per backend/db.js (getOrders, lines 163-330), this means loading and mapping every matched order (and items) before pagination, which defeats scalability and can block the request path under larger datasets.

Suggested direction
-  const allOrders = database.getOrders({ spotId, userId });
-  const total = allOrders.length;
-  const paginatedOrders = allOrders.slice(offset, offset + limit);
+  const { data: paginatedOrders, total } = database.getOrders({
+    spotId,
+    userId,
+    limit,
+    offset
+  });

Then update backend/db.js:getOrders to:

  • run COUNT(*) for total
  • run paged select with LIMIT ? OFFSET ?
  • fetch/map items only for paged order IDs
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/server.js` around lines 131 - 138, The code currently calls
database.getOrders without pagination and then slices the full result in
server.js, which forces a full fetch and mapping; update database.getOrders (in
backend/db.js) to accept limit and offset, perform a COUNT(*) query to compute
total, run the paged SELECT with LIMIT ? OFFSET ? to fetch only the requested
orders, then fetch/map items only for the paged order IDs; change the server
call (database.getOrders) to pass limit and offset and consume the new return
shape (e.g., { total, orders }) so server.js uses the DB-provided total and
paged orders directly.

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.

1 participant