Skip to content

Commit 8587a8e

Browse files
authored
Merge pull request #842 from topcoder-platform/PM-1314
PM-1314 Make grouping by status optional
2 parents f8cf3b4 + eb88f39 commit 8587a8e

File tree

1 file changed

+20
-4
lines changed
  • src/routes/copilotOpportunity

1 file changed

+20
-4
lines changed

src/routes/copilotOpportunity/list.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ module.exports = [
2121
const pageSize = parseInt(req.query.pageSize, 10) || DEFAULT_PAGE_SIZE;
2222
const offset = (page - 1) * pageSize;
2323
const limit = pageSize;
24+
const noGroupingByStatus = req.query.noGrouping === 'true';
25+
26+
const baseOrder = [];
27+
28+
// If grouping is enabled (default), add custom ordering based on status
29+
if (!noGroupingByStatus) {
30+
baseOrder.push([
31+
models.Sequelize.literal(`
32+
CASE
33+
WHEN "CopilotOpportunity"."status" = 'active' THEN 0
34+
WHEN "CopilotOpportunity"."status" = 'cancelled' THEN 1
35+
WHEN "CopilotOpportunity"."status" = 'completed' THEN 2
36+
ELSE 3
37+
END
38+
`),
39+
'ASC',
40+
]);
41+
}
42+
baseOrder.push([sortParams[0], sortParams[1]]);
2443

2544
return models.CopilotOpportunity.findAll({
2645
include: [
@@ -34,10 +53,7 @@ module.exports = [
3453
attributes: ['name'],
3554
},
3655
],
37-
order: [
38-
[models.Sequelize.literal(`CASE WHEN "CopilotOpportunity"."status" = 'active' THEN 0 ELSE 1 END`), 'ASC'],
39-
[sortParams[0], sortParams[1]]
40-
],
56+
order: baseOrder,
4157
limit,
4258
offset,
4359
})

0 commit comments

Comments
 (0)