Skip to content

Commit b793329

Browse files
authored
Merge pull request #850 from topcoder-platform/pm-1650_1
fix(PM-1650): Added sorting to copilot requests API
2 parents c958c3c + 07e16d1 commit b793329

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ workflows:
149149
context : org-global
150150
filters:
151151
branches:
152-
only: ['develop', 'migration-setup', 'pm-1611']
152+
only: ['develop', 'migration-setup', 'pm-1650_1']
153153
- deployProd:
154154
context : org-global
155155
filters:

src/routes/copilotRequest/list.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,38 @@ module.exports = [
2727
if (sort.indexOf(' ') === -1) {
2828
sort += ' asc';
2929
}
30-
const sortableProps = ['createdAt asc', 'createdAt desc'];
30+
const sortableProps = [
31+
'createdAt asc',
32+
'createdAt desc',
33+
'projectName asc',
34+
'projectName desc',
35+
'opportunityTitle asc',
36+
'opportunityTitle desc',
37+
'projectType asc',
38+
'projectType desc',
39+
'status asc',
40+
'status desc',
41+
];
3142
if (_.indexOf(sortableProps, sort) < 0) {
3243
return util.handleError('Invalid sort criteria', null, req, next);
3344
}
34-
const sortParams = sort.split(' ');
45+
let sortParams = sort.split(' ');
46+
let order = [[sortParams[0], sortParams[1]]];
47+
const relationBasedSortParams = ['projectName'];
48+
const jsonBasedSortParams = ['opportunityTitle', 'projectType'];
49+
if (relationBasedSortParams.includes(sortParams[0])) {
50+
order = [
51+
[{model: models.Project, as: 'project'}, 'name', sortParams[1]],
52+
['id', 'DESC']
53+
]
54+
}
55+
56+
if (jsonBasedSortParams.includes(sortParams[0])) {
57+
order = [
58+
[models.sequelize.literal(`("CopilotRequest"."data"->>'${sortParams[0]}')`), sortParams[1]],
59+
['id', 'DESC'],
60+
]
61+
}
3562

3663
const whereCondition = projectId ? { projectId } : {};
3764

@@ -41,7 +68,7 @@ module.exports = [
4168
{ model: models.CopilotOpportunity, as: 'copilotOpportunity', required: false },
4269
{ model: models.Project, as: 'project', required: false },
4370
],
44-
order: [[sortParams[0], sortParams[1]]],
71+
order,
4572
limit: pageSize,
4673
offset,
4774
distinct: true,

0 commit comments

Comments
 (0)