Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ workflows:
context : org-global
filters:
branches:
only: ['develop', 'migration-setup', 'pm-1510']
only: ['develop', 'migration-setup', 'PM-1314']
- deployProd:
context : org-global
filters:
Expand Down
24 changes: 20 additions & 4 deletions src/routes/copilotOpportunity/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ module.exports = [
const pageSize = parseInt(req.query.pageSize, 10) || DEFAULT_PAGE_SIZE;
const offset = (page - 1) * pageSize;
const limit = pageSize;
const noGroupingByStatus = req.query.noGrouping === 'true';

Choose a reason for hiding this comment

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

Consider renaming the variable noGroupingByStatus to something more intuitive, such as isGroupingByStatusDisabled, to clarify that it represents a boolean flag indicating whether grouping is disabled.


const baseOrder = [];

// If grouping is enabled (default), add custom ordering based on status
if (!noGroupingByStatus) {
baseOrder.push([
models.Sequelize.literal(`
CASE
WHEN "CopilotOpportunity"."status" = 'active' THEN 0
WHEN "CopilotOpportunity"."status" = 'cancelled' THEN 1
WHEN "CopilotOpportunity"."status" = 'completed' THEN 2
ELSE 3
END
`),
'ASC',
]);
}
baseOrder.push([sortParams[0], sortParams[1]]);

Choose a reason for hiding this comment

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

Ensure that sortParams is properly validated before being used in baseOrder.push([sortParams[0], sortParams[1]]);. This will prevent potential runtime errors if sortParams is undefined or not an array with at least two elements.


return models.CopilotOpportunity.findAll({
include: [
Expand All @@ -34,10 +53,7 @@ module.exports = [
attributes: ['name'],
},
],
order: [
[models.Sequelize.literal(`CASE WHEN "CopilotOpportunity"."status" = 'active' THEN 0 ELSE 1 END`), 'ASC'],
[sortParams[0], sortParams[1]]
],
order: baseOrder,
limit,
offset,
})
Expand Down