Skip to content

add support for filtering on events #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ paths:
type: array
items:
type: string
- name: includeAllTags
in: query
description: >-
Require all provided tags to be present on a challenge for a match
required: false
default: true
type: boolean
- name: events
in: query
description: >-
Filter by multiple event IDs
required: false
type: array
items:
type: number
- name: includeAllEvents
in: query
description: >-
Require all provided events to be present on a challenge for a match
required: false
default: true
type: boolean
- name: projectId
in: query
description: 'Filter by v5 project id, exact match.'
Expand Down
18 changes: 16 additions & 2 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async function searchChallenges (currentUser, criteria) {
_.forIn(_.omit(criteria, ['types', 'tracks', 'typeIds', 'trackIds', 'type', 'name', 'trackId', 'typeId', 'description', 'page', 'perPage', 'tag',
'group', 'groups', 'memberId', 'ids', 'createdDateStart', 'createdDateEnd', 'updatedDateStart', 'updatedDateEnd', 'startDateStart', 'startDateEnd', 'endDateStart', 'endDateEnd',
'tags', 'registrationStartDateStart', 'registrationStartDateEnd', 'currentPhaseName', 'submissionStartDateStart', 'submissionStartDateEnd',
'registrationEndDateStart', 'registrationEndDateEnd', 'submissionEndDateStart', 'submissionEndDateEnd',
'registrationEndDateStart', 'registrationEndDateEnd', 'submissionEndDateStart', 'submissionEndDateEnd', 'includeAllEvents', 'events',
'forumId', 'track', 'reviewType', 'confidentialityType', 'directProjectId', 'sortBy', 'sortOrder', 'isLightweight', 'isTask', 'taskIsAssigned', 'taskMemberId']), (value, key) => {
if (!_.isUndefined(value)) {
const filter = { match_phrase: {} }
Expand Down Expand Up @@ -274,6 +274,18 @@ async function searchChallenges (currentUser, criteria) {
}
}

if (criteria.events) {
if (criteria.includeAllEvents) {
for (const e of criteria.events) {
boolQuery.push({ match_phrase: { 'events.id': e } })
}
} else {
for (const e of criteria.events) {
shouldQuery.push({ match: { 'events.id': e } })
}
}
}

const mustNotQuery = []

let groupsToFilter = []
Expand Down Expand Up @@ -577,7 +589,9 @@ searchChallenges.schema = {
ids: Joi.array().items(Joi.optionalId()).unique().min(1),
isTask: Joi.boolean(),
taskIsAssigned: Joi.boolean(),
taskMemberId: Joi.string()
taskMemberId: Joi.string(),
events: Joi.array().items(Joi.number()),
includeAllEvents: Joi.boolean().default(true)
})
}

Expand Down