Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 22 additions & 3 deletions src/routes/copilotRequest/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,30 @@ 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);
}
const sortParams = sort.split(' ');
let sortParams = sort.split(' ');
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 } : {};

Expand All @@ -41,7 +60,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,
Expand Down