Skip to content

Commit 17cf594

Browse files
committed
add search by legacyId
1 parent 37e9d50 commit 17cf594

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ workflows:
7272
branches:
7373
only:
7474
- dev
75+
- PLAT-2363
7576

7677
# Production builds are exectuted only on tagged commits to the
7778
# master branch.

src/services/ChallengeService.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,45 @@ async function ensureAcessibilityToModifiedGroups (currentUser, data, challenge)
118118
}
119119
}
120120

121+
async function searchByLegacyId (currentUser, legacyId, page, perPage) {
122+
const esQuery = {
123+
index: config.get('ES.ES_INDEX'),
124+
type: config.get('ES.ES_TYPE'),
125+
size: perPage,
126+
from: (page - 1) * perPage,
127+
body: {
128+
query: {
129+
term: {
130+
legacyId
131+
}
132+
},
133+
fields: ['id']
134+
}
135+
}
136+
137+
logger.debug(`es Query ${JSON.stringify(esQuery)}`)
138+
let docs
139+
try {
140+
docs = await esClient.search(esQuery)
141+
} catch (e) {
142+
logger.error(`Query Error from ES ${JSON.stringify(e)}`)
143+
docs = {
144+
hits: {
145+
hits: []
146+
}
147+
}
148+
}
149+
const ids = _.map(docs.hits.hits, item => item._source.id)
150+
const result = []
151+
for (const id of ids) {
152+
try {
153+
const challenge = await getChallenge(currentUser, id)
154+
result.push(challenge)
155+
} catch (e) {}
156+
}
157+
return result
158+
}
159+
121160
/**
122161
* Search challenges
123162
* @param {Object} currentUser the user who perform operation
@@ -129,6 +168,10 @@ async function searchChallenges (currentUser, criteria) {
129168

130169
const page = criteria.page || 1
131170
const perPage = criteria.perPage || 20
171+
if (!_.isUndefined(criteria.legacyId)) {
172+
const result = searchByLegacyId(currentUser, criteria.legacyId, page, perPage)
173+
return { total: result.length, page, perPage, result }
174+
}
132175
const boolQuery = []
133176
let sortByScore = false
134177
const matchPhraseKeys = [

0 commit comments

Comments
 (0)