From b8343b9393062944c1f99b7026cebe401e322bfb Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 19 Aug 2025 21:38:30 +0200 Subject: [PATCH 1/4] fix: added sorting functionality --- src/routes/copilotRequest/list.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/routes/copilotRequest/list.js b/src/routes/copilotRequest/list.js index 27664733..a9dd9531 100644 --- a/src/routes/copilotRequest/list.js +++ b/src/routes/copilotRequest/list.js @@ -31,7 +31,11 @@ module.exports = [ if (_.indexOf(sortableProps, sort) < 0) { return util.handleError('Invalid sort criteria', null, req, next); } - const sortParams = sort.split(' '); + let sortParams = sort.split(' '); + let order = [[sortParams[0], sortParams[1]]] + if (sortParams[0] === 'projectName') { + order = [[{model: models.Project, as: 'project'}, 'name', sortParams[1]]] + } const whereCondition = projectId ? { projectId } : {}; @@ -41,7 +45,7 @@ module.exports = [ { model: models.CopilotOpportunity, as: 'copilotOpportunity', required: false }, { model: models.Project, as: 'project', required: false }, ], - order: [[sortParams[0], sortParams[1]]], + order, limit: pageSize, offset, distinct: true, From dea96ef792773e9034b44500728b35b125e09ba9 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 19 Aug 2025 21:38:36 +0200 Subject: [PATCH 2/4] fix: added sorting functionality --- src/routes/copilotRequest/list.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/routes/copilotRequest/list.js b/src/routes/copilotRequest/list.js index a9dd9531..89d7bb4f 100644 --- a/src/routes/copilotRequest/list.js +++ b/src/routes/copilotRequest/list.js @@ -27,16 +27,31 @@ module.exports = [ if (sort.indexOf(' ') === -1) { sort += ' asc'; } - const sortableProps = ['createdAt asc', 'createdAt desc']; + const sortableProps = [ + 'createdAt asc', + 'createdAt desc', + 'projectName asc', + 'projectName desc', + 'opportunityTitle asc', + 'opportunityTitle desc', + 'projectType asc', + 'projectType desc', + ]; if (_.indexOf(sortableProps, sort) < 0) { return util.handleError('Invalid sort criteria', null, req, next); } let sortParams = sort.split(' '); - let order = [[sortParams[0], sortParams[1]]] - if (sortParams[0] === 'projectName') { + let order = [[sortParams[0], sortParams[1]]]; + const relationBasedSortParams = ['projectName']; + const jsonBasedSortParams = ['opportunityTitle', 'projectType']; + if (relationBasedSortParams.includes(sortParams[0])) { order = [[{model: models.Project, as: 'project'}, 'name', sortParams[1]]] } + if (jsonBasedSortParams.includes(sortParams[0])) { + order = [[models.sequelize.literal(`("CopilotRequest"."data"->>'${sortParams[0]}')`), sortParams[1]]] + } + const whereCondition = projectId ? { projectId } : {}; return models.CopilotRequest.findAndCountAll({ From 8989bbe1812341ec30b81ba88895a1b5ca3f83b1 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 19 Aug 2025 21:39:01 +0200 Subject: [PATCH 3/4] fix: added sorting functionality --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3f9d7062..4c95c5d7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -149,7 +149,7 @@ workflows: context : org-global filters: branches: - only: ['develop', 'migration-setup', 'pm-1611'] + only: ['develop', 'migration-setup', 'pm-1650_1'] - deployProd: context : org-global filters: From 07e16d12f86b2c3c2c98bfeebc5ffb385d784fa4 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Tue, 19 Aug 2025 23:48:37 +0200 Subject: [PATCH 4/4] fix: sorting --- src/routes/copilotRequest/list.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/routes/copilotRequest/list.js b/src/routes/copilotRequest/list.js index 89d7bb4f..ef36d26b 100644 --- a/src/routes/copilotRequest/list.js +++ b/src/routes/copilotRequest/list.js @@ -36,6 +36,8 @@ module.exports = [ 'opportunityTitle desc', 'projectType asc', 'projectType desc', + 'status asc', + 'status desc', ]; if (_.indexOf(sortableProps, sort) < 0) { return util.handleError('Invalid sort criteria', null, req, next); @@ -45,11 +47,17 @@ module.exports = [ const relationBasedSortParams = ['projectName']; const jsonBasedSortParams = ['opportunityTitle', 'projectType']; if (relationBasedSortParams.includes(sortParams[0])) { - order = [[{model: models.Project, as: 'project'}, 'name', sortParams[1]]] + order = [ + [{model: models.Project, as: 'project'}, 'name', sortParams[1]], + ['id', 'DESC'] + ] } if (jsonBasedSortParams.includes(sortParams[0])) { - order = [[models.sequelize.literal(`("CopilotRequest"."data"->>'${sortParams[0]}')`), sortParams[1]]] + order = [ + [models.sequelize.literal(`("CopilotRequest"."data"->>'${sortParams[0]}')`), sortParams[1]], + ['id', 'DESC'], + ] } const whereCondition = projectId ? { projectId } : {};