@@ -109,6 +109,15 @@ async function searchChallenges (currentUser, criteria) {
109109 const page = criteria . page || 1
110110 const perPage = criteria . perPage || 20
111111 const boolQuery = [ ]
112+ const matchPhraseKeys = [
113+ 'id' ,
114+ 'timelineTemplateId' ,
115+ 'projectId' ,
116+ 'legacyId' ,
117+ 'status' ,
118+ 'createdBy' ,
119+ 'updatedBy'
120+ ]
112121
113122 const includedTrackIds = _ . isArray ( criteria . trackIds ) ? criteria . trackIds : [ ]
114123
@@ -151,18 +160,28 @@ async function searchChallenges (currentUser, criteria) {
151160 includedTrackIds . push ( criteria . trackId )
152161 }
153162
154- _ . forIn ( _ . omit ( criteria , [ 'types' , 'tracks' , 'typeIds' , 'trackIds' , 'type' , 'name' , 'trackId' , 'typeId' , 'description' , 'page' , 'perPage' , 'tag' ,
155- 'group' , 'groups' , 'memberId' , 'ids' , 'createdDateStart' , 'createdDateEnd' , 'updatedDateStart' , 'updatedDateEnd' , 'startDateStart' , 'startDateEnd' , 'endDateStart' , 'endDateEnd' ,
156- 'tags' , 'registrationStartDateStart' , 'registrationStartDateEnd' , 'currentPhaseName' , 'submissionStartDateStart' , 'submissionStartDateEnd' ,
157- 'registrationEndDateStart' , 'registrationEndDateEnd' , 'submissionEndDateStart' , 'submissionEndDateEnd' , 'includeAllEvents' , 'events' ,
158- 'forumId' , 'track' , 'reviewType' , 'confidentialityType' , 'directProjectId' , 'sortBy' , 'sortOrder' , 'isLightweight' , 'isTask' , 'taskIsAssigned' , 'taskMemberId' ] ) , ( value , key ) => {
163+ _ . forIn ( _ . pick ( criteria , matchPhraseKeys ) , ( value , key ) => {
159164 if ( ! _ . isUndefined ( value ) ) {
160165 const filter = { match_phrase : { } }
161166 filter . match_phrase [ key ] = value
162167 boolQuery . push ( filter )
163168 }
164169 } )
165170
171+ _ . forEach ( _ . keys ( criteria ) , ( key ) => {
172+ if ( _ . toString ( key ) . indexOf ( 'meta.' ) > - 1 ) {
173+ // Parse and use metadata key
174+ if ( ! _ . isUndefined ( criteria [ key ] ) ) {
175+ const metaKey = key . split ( 'meta.' ) [ 1 ]
176+ const metaMustQuery = { must : [
177+ { match_phrase : { 'metadata.name' : metaKey } } ,
178+ { match_phrase : { 'metadata.value' : criteria [ key ] } }
179+ ] }
180+ boolQuery . push ( metaMustQuery )
181+ }
182+ }
183+ } )
184+
166185 if ( includedTypeIds . length > 0 ) {
167186 boolQuery . push ( {
168187 bool : {
@@ -594,7 +613,7 @@ searchChallenges.schema = {
594613 taskMemberId : Joi . string ( ) ,
595614 events : Joi . array ( ) . items ( Joi . number ( ) ) ,
596615 includeAllEvents : Joi . boolean ( ) . default ( true )
597- } )
616+ } ) . unknown ( true )
598617}
599618
600619/**
0 commit comments