@@ -110,6 +110,9 @@ async function searchChallenges (currentUser, criteria) {
110
110
const perPage = criteria . perPage || 20
111
111
const boolQuery = [ ]
112
112
113
+ const includedTrackIds = [ ]
114
+ const includedTypeIds = [ ]
115
+
113
116
if ( criteria . type ) {
114
117
const typeSearchRes = await ChallengeTypeService . searchChallengeTypes ( { abbreviation : criteria . type } )
115
118
if ( typeSearchRes . total > 0 ) {
@@ -123,8 +126,32 @@ async function searchChallenges (currentUser, criteria) {
123
126
}
124
127
}
125
128
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' ,
128
155
'tags' , 'registrationStartDateStart' , 'registrationStartDateEnd' , 'currentPhaseName' , 'submissionStartDateStart' , 'submissionStartDateEnd' ,
129
156
'registrationEndDateStart' , 'registrationEndDateEnd' , 'submissionEndDateStart' , 'submissionEndDateEnd' ,
130
157
'forumId' , 'track' , 'reviewType' , 'confidentialityType' , 'directProjectId' , 'sortBy' , 'sortOrder' , 'isLightweight' , 'isTask' , 'taskIsAssigned' , 'taskMemberId' ] ) , ( value , key ) => {
@@ -135,6 +162,22 @@ async function searchChallenges (currentUser, criteria) {
135
162
}
136
163
} )
137
164
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
+
138
181
if ( criteria . name ) {
139
182
boolQuery . push ( { match : { name : `.*${ criteria . name } .*` } } )
140
183
}
@@ -306,7 +349,7 @@ async function searchChallenges (currentUser, criteria) {
306
349
// FIXME: Tech Debt
307
350
let excludeTasks = false
308
351
// 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 ) ) {
310
353
excludeTasks = true
311
354
}
312
355
if ( ! _ . isUndefined ( criteria . memberId ) ) {
@@ -504,6 +547,10 @@ searchChallenges.schema = {
504
547
id : Joi . optionalId ( ) ,
505
548
confidentialityType : Joi . string ( ) ,
506
549
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 ( ) ) ,
507
554
typeId : Joi . optionalId ( ) ,
508
555
trackId : Joi . optionalId ( ) ,
509
556
type : Joi . string ( ) ,
0 commit comments