Skip to content

Add support to search challenges by type.abbreviation #178

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 3 commits into from
Jun 16, 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
7 changes: 6 additions & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ paths:
in: query
description: Filter by directProjectId
type: integer
- name: type
in: query
description: Filter by type abbreviation, exact match. If provided, the typeId will be ignored
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. Add something similar to the description of typeId. "If type is provided, typeId will be ignored". People don't read up :)

required: false
type: string
- name: typeId
in: query
description: Filter by type id, exact match
description: Filter by type id, exact match. If type is provided, typeId will be ignored
required: false
type: string
format: UUID
Expand Down
12 changes: 11 additions & 1 deletion src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const models = require('../models')
const HttpStatus = require('http-status-codes')
const moment = require('moment')
const phaseService = require('./PhaseService')
const challengeTypeService = require('./ChallengeTypeService')

const esClient = helper.getESClient()

Expand Down Expand Up @@ -87,7 +88,15 @@ async function searchChallenges (currentUser, criteria) {
const page = criteria.page || 1
const perPage = criteria.perPage || 20
const boolQuery = []
_.forIn(_.omit(criteria, ['name', 'description', 'page', 'perPage', 'tag', 'group', 'groups', 'memberId', 'ids', 'createdDateStart', 'createdDateEnd',

if (criteria.type) {
const typeSearchRes = await challengeTypeService.searchChallengeTypes({ abbreviation: criteria.type })
if (typeSearchRes.total > 0) {
criteria.typeId = _.get(typeSearchRes, 'result[0].id')
}
}

_.forIn(_.omit(criteria, ['type', 'name', 'description', 'page', 'perPage', 'tag', 'group', 'groups', 'memberId', 'ids', 'createdDateStart', 'createdDateEnd',
'updatedDateStart', 'updatedDateEnd', 'startDateStart', 'startDateEnd', 'endDateStart', 'endDateEnd',
'forumId', 'track', 'reviewType', 'confidentialityType', 'directProjectId', 'sortBy', 'sortOrder']), (value, key) => {
if (!_.isUndefined(value)) {
Expand Down Expand Up @@ -294,6 +303,7 @@ searchChallenges.schema = {
confidentialityType: Joi.string(),
directProjectId: Joi.number(),
typeId: Joi.optionalId(),
type: Joi.string(),
track: Joi.string(),
name: Joi.string(),
description: Joi.string(),
Expand Down