@@ -118,6 +118,45 @@ async function ensureAcessibilityToModifiedGroups (currentUser, data, challenge)
118
118
}
119
119
}
120
120
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
+
121
160
/**
122
161
* Search challenges
123
162
* @param {Object } currentUser the user who perform operation
@@ -129,6 +168,10 @@ async function searchChallenges (currentUser, criteria) {
129
168
130
169
const page = criteria . page || 1
131
170
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
+ }
132
175
const boolQuery = [ ]
133
176
let sortByScore = false
134
177
const matchPhraseKeys = [
0 commit comments