Skip to content

Commit d149fa2

Browse files
fix sorting issue
1 parent 8da4806 commit d149fa2

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

app-constants.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ const challengeTracks = {
7070
QA: 'QA'
7171
}
7272

73+
const challengeTextSortField = {
74+
Name: 'name',
75+
TypeId: 'typeId'
76+
}
77+
7378
module.exports = {
7479
UserRoles,
7580
prizeSetTypes,
@@ -78,5 +83,6 @@ module.exports = {
7883
EVENT_ORIGINATOR,
7984
EVENT_MIME_TYPE,
8085
Topics,
81-
challengeTracks
86+
challengeTracks,
87+
challengeTextSortField
8288
}

src/services/ChallengeService.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ async function searchChallenges (currentUser, criteria) {
251251
if (criteria.endDateEnd) {
252252
boolQuery.push({ range: { endDate: { lte: criteria.endDateEnd } } })
253253
}
254-
const sortByProp = criteria.sortBy ? criteria.sortBy : 'created'
254+
255+
let sortByProp = criteria.sortBy ? criteria.sortBy : 'created'
256+
// If property to sort is text, then use its sub-field 'keyword' for sorting
257+
sortByProp = _.includes(constants.challengeTextSortField, sortByProp) ? sortByProp + '.keyword' : sortByProp
255258
const sortOrderProp = criteria.sortOrder ? criteria.sortOrder : 'desc'
256259

257260
const mustQuery = []

0 commit comments

Comments
 (0)