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 = [
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 } )
You can’t perform that action at this time.
0 commit comments