From 7e7b51775903ba8f0f9937558376d3d2761c73a2 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Tue, 12 Sep 2023 15:51:14 -0400 Subject: [PATCH] feat: default pagination --- src/controllers/project.controller.js | 16 ++++++++++++++++ src/controllers/units.controller.js | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/controllers/project.controller.js b/src/controllers/project.controller.js index 28f577b2..3db3872a 100644 --- a/src/controllers/project.controller.js +++ b/src/controllers/project.controller.js @@ -127,6 +127,22 @@ export const findAll = async (req, res) => { order, } = req.query; + if (!page) { + let redirectUrl = `${req.baseUrl}?page=1&limit=10`; + + if (Object.keys(req.query).length > 0) { + redirectUrl = redirectUrl.concat( + '&', + Object.keys(req.query) + .map((key) => `${key}=${req.query[key]}`) + .join('&'), + ); + } + + // Redirect to the modified URL + return res.redirect(301, redirectUrl); + } + let where = orgUid != null && orgUid !== 'all' ? { orgUid } : undefined; if (filter) { diff --git a/src/controllers/units.controller.js b/src/controllers/units.controller.js index 3d103ba0..133dda0c 100644 --- a/src/controllers/units.controller.js +++ b/src/controllers/units.controller.js @@ -133,6 +133,22 @@ export const findAll = async (req, res) => { filter, } = req.query; + if (!page) { + let redirectUrl = `${req.baseUrl}?page=1&limit=10`; + + if (Object.keys(req.query).length > 0) { + redirectUrl = redirectUrl.concat( + '&', + Object.keys(req.query) + .map((key) => `${key}=${req.query[key]}`) + .join('&'), + ); + } + + // Redirect to the modified URL + return res.redirect(301, redirectUrl); + } + let where = orgUid != null && orgUid !== 'all' ? { orgUid } : undefined; if (filter) {