Skip to content

Product route: No pagination on list endpoint #17

@thomasiverson

Description

@thomasiverson

Severity: Medium

Category: Performance

Description

In api/src/routes/product.ts, the GET / endpoint returns the full product array on every call with no pagination support. As the dataset grows, this becomes increasingly expensive to serialize and transfer.

Suggested Fix

Support ?page=1&limit=20 query parameters with sensible defaults:

router.get('/', (req, res) => {
  const page = parseInt(req.query.page as string, 10) || 1;
  const limit = parseInt(req.query.limit as string, 10) || 20;
  const start = (page - 1) * limit;
  const paginatedProducts = products.slice(start, start + limit);
  res.json({
    data: paginatedProducts,
    total: products.length,
    page,
    limit,
  });
});

Note: this would be a breaking change for the frontend, which currently expects a bare array response.

Affected File

  • api/src/routes/product.ts (GET / handler, lines 108-110)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions