File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
src/routes/copilotOpportunity Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,25 @@ module.exports = [
21
21
const pageSize = parseInt ( req . query . pageSize , 10 ) || DEFAULT_PAGE_SIZE ;
22
22
const offset = ( page - 1 ) * pageSize ;
23
23
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 ] ] ) ;
24
43
25
44
return models . CopilotOpportunity . findAll ( {
26
45
include : [
@@ -34,10 +53,7 @@ module.exports = [
34
53
attributes : [ 'name' ] ,
35
54
} ,
36
55
] ,
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 ,
41
57
limit,
42
58
offset,
43
59
} )
You can’t perform that action at this time.
0 commit comments