@@ -110,6 +110,9 @@ async function searchChallenges (currentUser, criteria) {
110110 const perPage = criteria . perPage || 20
111111 const boolQuery = [ ]
112112
113+ const includedTrackIds = [ ]
114+ const includedTypeIds = [ ]
115+
113116 if ( criteria . type ) {
114117 const typeSearchRes = await ChallengeTypeService . searchChallengeTypes ( { abbreviation : criteria . type } )
115118 if ( typeSearchRes . total > 0 ) {
@@ -123,8 +126,32 @@ async function searchChallenges (currentUser, criteria) {
123126 }
124127 }
125128
126- _ . forIn ( _ . omit ( criteria , [ 'type' , 'name' , 'description' , 'page' , 'perPage' , 'tag' , 'group' , 'groups' , 'memberId' , 'ids' , 'createdDateStart' , 'createdDateEnd' ,
127- 'updatedDateStart' , 'updatedDateEnd' , 'startDateStart' , 'startDateEnd' , 'endDateStart' , 'endDateEnd' ,
129+ if ( criteria . types ) {
130+ for ( const t of criteria . types ) {
131+ const typeSearchRes = await ChallengeTypeService . searchChallengeTypes ( { abbreviation : t } )
132+ if ( typeSearchRes . total > 0 ) {
133+ includedTypeIds . push ( _ . get ( typeSearchRes , 'result[0].id' ) )
134+ }
135+ }
136+ }
137+ if ( criteria . tracks ) {
138+ for ( const t of criteria . types ) {
139+ const trackSearchRes = await ChallengeTrackService . searchChallengeTracks ( { abbreviation : t } )
140+ if ( trackSearchRes . total > 0 ) {
141+ includedTrackIds . push ( _ . get ( trackSearchRes , 'result[0].id' ) )
142+ }
143+ }
144+ }
145+
146+ if ( criteria . typeId ) {
147+ includedTypeIds . push ( criteria . typeId )
148+ }
149+ if ( criteria . trackId ) {
150+ includedTrackIds . push ( criteria . trackId )
151+ }
152+
153+ _ . forIn ( _ . omit ( criteria , [ 'types' , 'tracks' , 'typeIds' , 'trackIds' , 'type' , 'name' , 'trackId' , 'typeId' , 'description' , 'page' , 'perPage' , 'tag' ,
154+ 'group' , 'groups' , 'memberId' , 'ids' , 'createdDateStart' , 'createdDateEnd' , 'updatedDateStart' , 'updatedDateEnd' , 'startDateStart' , 'startDateEnd' , 'endDateStart' , 'endDateEnd' ,
128155 'tags' , 'registrationStartDateStart' , 'registrationStartDateEnd' , 'currentPhaseName' , 'submissionStartDateStart' , 'submissionStartDateEnd' ,
129156 'registrationEndDateStart' , 'registrationEndDateEnd' , 'submissionEndDateStart' , 'submissionEndDateEnd' ,
130157 'forumId' , 'track' , 'reviewType' , 'confidentialityType' , 'directProjectId' , 'sortBy' , 'sortOrder' , 'isLightweight' , 'isTask' , 'taskIsAssigned' , 'taskMemberId' ] ) , ( value , key ) => {
@@ -135,6 +162,22 @@ async function searchChallenges (currentUser, criteria) {
135162 }
136163 } )
137164
165+ if ( includedTypeIds . length > 0 ) {
166+ boolQuery . push ( {
167+ bool : {
168+ should : _ . map ( includedTypeIds , t => ( { match_phrase : { typeId : t } } ) )
169+ }
170+ } )
171+ }
172+
173+ if ( includedTrackIds . length > 0 ) {
174+ boolQuery . push ( {
175+ bool : {
176+ should : _ . map ( includedTrackIds , t => ( { match_phrase : { trackId : t } } ) )
177+ }
178+ } )
179+ }
180+
138181 if ( criteria . name ) {
139182 boolQuery . push ( { match : { name : `.*${ criteria . name } .*` } } )
140183 }
@@ -306,7 +349,7 @@ async function searchChallenges (currentUser, criteria) {
306349 // FIXME: Tech Debt
307350 let excludeTasks = false
308351 // If you're not looking for a particular type or a specific challenge, exclude tasks
309- if ( _ . isUndefined ( criteria . type ) && _ . isUndefined ( criteria . typeId ) && _ . isUndefined ( criteria . legacyId ) ) {
352+ if ( _ . isUndefined ( criteria . type ) && includedTypeIds . length === 0 && _ . isUndefined ( criteria . legacyId ) ) {
310353 excludeTasks = true
311354 }
312355 if ( ! _ . isUndefined ( criteria . memberId ) ) {
@@ -504,6 +547,10 @@ searchChallenges.schema = {
504547 id : Joi . optionalId ( ) ,
505548 confidentialityType : Joi . string ( ) ,
506549 directProjectId : Joi . number ( ) ,
550+ typeIds : Joi . array ( ) . items ( Joi . optionalId ( ) ) ,
551+ trackIds : Joi . array ( ) . items ( Joi . optionalId ( ) ) ,
552+ types : Joi . array ( ) . items ( Joi . string ( ) ) ,
553+ tracks : Joi . array ( ) . items ( Joi . string ( ) ) ,
507554 typeId : Joi . optionalId ( ) ,
508555 trackId : Joi . optionalId ( ) ,
509556 type : Joi . string ( ) ,
0 commit comments