Skip to content

Commit 58a5cb0

Browse files
add support for filtering on events
1 parent 4371a68 commit 58a5cb0

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

docs/swagger.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,29 @@ paths:
174174
type: array
175175
items:
176176
type: string
177+
- name: includeAllTags
178+
in: query
179+
description: >-
180+
Require all provided tags to be present on a challenge for a match
181+
required: false
182+
default: true
183+
type: boolean
184+
- name: events
185+
in: query
186+
description: >-
187+
Filter by multiple event names, case-insensitive, partial matches are
188+
allowed.
189+
required: false
190+
type: array
191+
items:
192+
type: string
193+
- name: includeAllEvents
194+
in: query
195+
description: >-
196+
Require all provided events to be present on a challenge for a match
197+
required: false
198+
default: true
199+
type: boolean
177200
- name: projectId
178201
in: query
179202
description: 'Filter by v5 project id, exact match.'

src/services/ChallengeService.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ async function searchChallenges (currentUser, criteria) {
154154
_.forIn(_.omit(criteria, ['types', 'tracks', 'typeIds', 'trackIds', 'type', 'name', 'trackId', 'typeId', 'description', 'page', 'perPage', 'tag',
155155
'group', 'groups', 'memberId', 'ids', 'createdDateStart', 'createdDateEnd', 'updatedDateStart', 'updatedDateEnd', 'startDateStart', 'startDateEnd', 'endDateStart', 'endDateEnd',
156156
'tags', 'registrationStartDateStart', 'registrationStartDateEnd', 'currentPhaseName', 'submissionStartDateStart', 'submissionStartDateEnd',
157-
'registrationEndDateStart', 'registrationEndDateEnd', 'submissionEndDateStart', 'submissionEndDateEnd',
157+
'registrationEndDateStart', 'registrationEndDateEnd', 'submissionEndDateStart', 'submissionEndDateEnd', 'includeAllEvents', 'events',
158158
'forumId', 'track', 'reviewType', 'confidentialityType', 'directProjectId', 'sortBy', 'sortOrder', 'isLightweight', 'isTask', 'taskIsAssigned', 'taskMemberId']), (value, key) => {
159159
if (!_.isUndefined(value)) {
160160
const filter = { match_phrase: {} }
@@ -274,6 +274,18 @@ async function searchChallenges (currentUser, criteria) {
274274
}
275275
}
276276

277+
if (criteria.events) {
278+
if (criteria.includeAllEvents) {
279+
for (const e of criteria.events) {
280+
boolQuery.push({ match_phrase: { 'events.name': e } })
281+
}
282+
} else {
283+
for (const e of criteria.events) {
284+
shouldQuery.push({ match: { 'events.name': e } })
285+
}
286+
}
287+
}
288+
277289
const mustNotQuery = []
278290

279291
let groupsToFilter = []
@@ -577,7 +589,9 @@ searchChallenges.schema = {
577589
ids: Joi.array().items(Joi.optionalId()).unique().min(1),
578590
isTask: Joi.boolean(),
579591
taskIsAssigned: Joi.boolean(),
580-
taskMemberId: Joi.string()
592+
taskMemberId: Joi.string(),
593+
events: Joi.array().items(Joi.string()),
594+
includeAllEvents: Joi.boolean().default(true)
581595
})
582596
}
583597

0 commit comments

Comments
 (0)