From 1019284d292c66386d4ce4cfa9789f8ff770dc48 Mon Sep 17 00:00:00 2001 From: Anthony Benites <104385099+ec2sw@users.noreply.github.com> Date: Mon, 6 Jun 2022 08:36:22 -0400 Subject: [PATCH] fix: fix pagination issues on projects and units search --- src/controllers/project.controller.js | 25 +++++++++++-------------- src/controllers/units.controller.js | 12 +++--------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/controllers/project.controller.js b/src/controllers/project.controller.js index 5d4a202c..deb19649 100644 --- a/src/controllers/project.controller.js +++ b/src/controllers/project.controller.js @@ -132,7 +132,6 @@ export const findAll = async (req, res) => { columns = ['warehouseProjectId']; } - let results; let pagination = paginationParams(page, limit); if (xls) { @@ -140,7 +139,7 @@ export const findAll = async (req, res) => { } if (search) { - const ftsResults = await Project.fts(search, orgUid, pagination, columns); + const ftsResults = await Project.fts(search, orgUid, {}, columns); const mappedResults = ftsResults.rows.map((ftsResult) => _.get(ftsResult, 'dataValues.warehouseProjectId'), ); @@ -154,19 +153,17 @@ export const findAll = async (req, res) => { }; } - if (!results) { - const query = { - ...columnsToInclude(columns, includes), - ...pagination, - }; + const query = { + ...columnsToInclude(columns, includes), + ...pagination, + }; - results = await Project.findAndCountAll({ - distinct: true, - where, - order: [['timeStaged', 'DESC']], - ...query, - }); - } + const results = await Project.findAndCountAll({ + distinct: true, + where, + order: [['timeStaged', 'DESC']], + ...query, + }); const response = optionallyPaginatedResponse(results, page, limit); diff --git a/src/controllers/units.controller.js b/src/controllers/units.controller.js index a207bd4a..ba7e5356 100644 --- a/src/controllers/units.controller.js +++ b/src/controllers/units.controller.js @@ -132,12 +132,7 @@ export const findAll = async (req, res) => { columns = ['warehouseUnitId']; } - let results; - let pagination = paginationParams(page, limit); - - if (xls) { - pagination = { page: undefined, limit: undefined }; - } + let pagination = { page: undefined, limit: undefined }; if (search) { const ftsResults = await Unit.fts( @@ -169,15 +164,14 @@ export const findAll = async (req, res) => { resultOrder = [['timeStaged', 'ASC']]; } - if (!results) { - results = await Unit.findAndCountAll({ + const results = await Unit.findAndCountAll({ where, distinct: true, order: resultOrder, ...columnsToInclude(columns, includes), ...paginationParams(page, limit), }); - } + const response = optionallyPaginatedResponse(results, page, limit);