Skip to content

Commit

Permalink
fix: fix pagination issues on projects and units search
Browse files Browse the repository at this point in the history
  • Loading branch information
ec2sw committed Jun 6, 2022
1 parent 83d5b1a commit 1019284
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
25 changes: 11 additions & 14 deletions src/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,14 @@ export const findAll = async (req, res) => {
columns = ['warehouseProjectId'];
}

let results;
let pagination = paginationParams(page, limit);

if (xls) {
pagination = { page: undefined, limit: undefined };
}

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'),
);
Expand All @@ -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);

Expand Down
12 changes: 3 additions & 9 deletions src/controllers/units.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 1019284

Please sign in to comment.