diff --git a/docs/swagger.yaml b/docs/swagger.yaml index c3b7a958..d7c985b3 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -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 + 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 diff --git a/src/services/ChallengeService.js b/src/services/ChallengeService.js index fb3c9619..39be0ea6 100644 --- a/src/services/ChallengeService.js +++ b/src/services/ChallengeService.js @@ -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() @@ -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)) { @@ -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(),