Skip to content

Commit fc6b982

Browse files
authored
Merge pull request #727 from topcoder-platform/TOP-2364
Fix up the sortBy parameter - (Top 2364)
2 parents 97b0671 + a7f5de4 commit fc6b982

File tree

2 files changed

+15
-83
lines changed

2 files changed

+15
-83
lines changed

.circleci/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ workflows:
8787
only:
8888
- dev
8989
- feature/top-262-projectid-non-mandatory
90+
- TOP-2364
9091

9192
- "build-qa":
9293
context: org-global

src/services/ChallengeService.js

+14-83
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ async function searchChallenges(currentUser, criteria) {
153153

154154
const _hasAdminRole = hasAdminRole(currentUser);
155155

156-
const includeSelfService =
157-
currentUser &&
158-
(currentUser.isMachine ||
159-
_hasAdminRole ||
160-
_.includes(config.SELF_SERVICE_WHITELIST_HANDLES, currentUser.handle.toLowerCase()));
161-
162156
const includedTrackIds = _.isArray(criteria.trackIds) ? criteria.trackIds : [];
163157
const includedTypeIds = _.isArray(criteria.typeIds) ? criteria.typeIds : [];
164158

@@ -463,6 +457,18 @@ async function searchChallenges(currentUser, criteria) {
463457
}
464458

465459
let sortByProp = criteria.sortBy ? criteria.sortBy : "created";
460+
461+
// Add '.keyword' to the end of the sort by prop for certain fields
462+
// (TOP-2364)
463+
if(sortByProp == "updatedBy" ||
464+
sortByProp == "createdBy" ||
465+
sortByProp == "name" ||
466+
sortByProp == "type" ||
467+
sortByProp == "status") {
468+
469+
sortByProp = sortByProp + ".keyword";
470+
}
471+
466472
const sortOrderProp = criteria.sortOrder ? criteria.sortOrder : "desc";
467473

468474
const mustQuery = [];
@@ -647,83 +653,6 @@ async function searchChallenges(currentUser, criteria) {
647653
});
648654
}
649655

650-
if (!includeSelfService) {
651-
mustQuery.push({
652-
bool: {
653-
should: [
654-
{ bool: { must_not: { exists: { field: "legacy.selfService" } } } },
655-
...(currentUser
656-
? [
657-
{
658-
bool: {
659-
must: [
660-
{
661-
bool: {
662-
must_not: {
663-
match_phrase: {
664-
status: constants.challengeStatuses.New,
665-
},
666-
},
667-
},
668-
},
669-
{
670-
bool: {
671-
must_not: {
672-
match_phrase: {
673-
status: constants.challengeStatuses.Draft,
674-
},
675-
},
676-
},
677-
},
678-
{
679-
bool: {
680-
must_not: {
681-
match_phrase: {
682-
status: constants.challengeStatuses.Approved,
683-
},
684-
},
685-
},
686-
},
687-
],
688-
},
689-
},
690-
{
691-
bool: {
692-
must: { match_phrase: { createdBy: currentUser.handle } },
693-
},
694-
},
695-
]
696-
: [
697-
{
698-
bool: {
699-
should: [
700-
{
701-
bool: {
702-
must: {
703-
match_phrase: {
704-
status: constants.challengeStatuses.Active,
705-
},
706-
},
707-
},
708-
},
709-
{
710-
bool: {
711-
must: {
712-
match_phrase: {
713-
status: constants.challengeStatuses.Completed,
714-
},
715-
},
716-
},
717-
},
718-
],
719-
},
720-
},
721-
]),
722-
],
723-
},
724-
});
725-
}
726-
727656
if (groupsQuery.length > 0) {
728657
mustQuery.push({
729658
bool: {
@@ -787,6 +716,7 @@ async function searchChallenges(currentUser, criteria) {
787716
],
788717
},
789718
};
719+
790720
// Search with constructed query
791721
let docs;
792722
try {
@@ -795,6 +725,7 @@ async function searchChallenges(currentUser, criteria) {
795725
? await esClient.search(esQuery)
796726
: (await esClient.search(esQuery)).body;
797727
} catch (e) {
728+
logger.error(JSON.stringify(e));
798729
// Catch error when the ES is fresh and has no data
799730
docs = {
800731
hits: {

0 commit comments

Comments
 (0)