Skip to content

Commit 9e51318

Browse files
Merge pull request #178 from topcoder-platform/issue-177
Add support to search challenges by type.abbreviation
2 parents 4472a96 + f564d38 commit 9e51318

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

docs/swagger.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,14 @@ paths:
6868
in: query
6969
description: Filter by directProjectId
7070
type: integer
71+
- name: type
72+
in: query
73+
description: Filter by type abbreviation, exact match. If provided, the typeId will be ignored
74+
required: false
75+
type: string
7176
- name: typeId
7277
in: query
73-
description: Filter by type id, exact match
78+
description: Filter by type id, exact match. If type is provided, typeId will be ignored
7479
required: false
7580
type: string
7681
format: UUID

src/services/ChallengeService.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const models = require('../models')
1414
const HttpStatus = require('http-status-codes')
1515
const moment = require('moment')
1616
const phaseService = require('./PhaseService')
17+
const challengeTypeService = require('./ChallengeTypeService')
1718

1819
const esClient = helper.getESClient()
1920

@@ -87,7 +88,15 @@ async function searchChallenges (currentUser, criteria) {
8788
const page = criteria.page || 1
8889
const perPage = criteria.perPage || 20
8990
const boolQuery = []
90-
_.forIn(_.omit(criteria, ['name', 'description', 'page', 'perPage', 'tag', 'group', 'groups', 'memberId', 'ids', 'createdDateStart', 'createdDateEnd',
91+
92+
if (criteria.type) {
93+
const typeSearchRes = await challengeTypeService.searchChallengeTypes({ abbreviation: criteria.type })
94+
if (typeSearchRes.total > 0) {
95+
criteria.typeId = _.get(typeSearchRes, 'result[0].id')
96+
}
97+
}
98+
99+
_.forIn(_.omit(criteria, ['type', 'name', 'description', 'page', 'perPage', 'tag', 'group', 'groups', 'memberId', 'ids', 'createdDateStart', 'createdDateEnd',
91100
'updatedDateStart', 'updatedDateEnd', 'startDateStart', 'startDateEnd', 'endDateStart', 'endDateEnd',
92101
'forumId', 'track', 'reviewType', 'confidentialityType', 'directProjectId', 'sortBy', 'sortOrder']), (value, key) => {
93102
if (!_.isUndefined(value)) {
@@ -294,6 +303,7 @@ searchChallenges.schema = {
294303
confidentialityType: Joi.string(),
295304
directProjectId: Joi.number(),
296305
typeId: Joi.optionalId(),
306+
type: Joi.string(),
297307
track: Joi.string(),
298308
name: Joi.string(),
299309
description: Joi.string(),

0 commit comments

Comments
 (0)