Skip to content

Commit eb88f39

Browse files
committed
PM-1314 Make grouping optional
1 parent ab5e2f0 commit eb88f39

File tree

1 file changed

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

1 file changed

+20
-3
lines changed

src/routes/copilotOpportunity/list.js

Lines changed: 20 additions & 3 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,9 +53,7 @@ module.exports = [
3453
attributes: ['name'],
3554
},
3655
],
37-
order: [
38-
[sortParams[0], sortParams[1]],
39-
],
56+
order: baseOrder,
4057
limit,
4158
offset,
4259
})

0 commit comments

Comments
 (0)