Skip to content

Commit 77b415e

Browse files
Merge pull request #400 from topcoder-platform/taas-api-multi-status
Taas api multi status
2 parents ae2b990 + 42261e9 commit 77b415e

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

docs/swagger.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,11 @@ paths:
624624
schema:
625625
type: string
626626
description: The external id.
627+
requestBody:
628+
content:
629+
application/json:
630+
schema:
631+
$ref: "#/components/schemas/JobCandidateSearchBody"
627632
responses:
628633
"200":
629634
description: OK
@@ -3996,6 +4001,14 @@ components:
39964001
type: string
39974002
example: "topcoder user"
39984003
description: "The user who updated the job last time.(Will get the user info from the token)"
4004+
JobCandidateSearchBody:
4005+
properties:
4006+
statuses:
4007+
type: array
4008+
items:
4009+
type: string
4010+
enum: ["open", "placed", "selected", "client rejected - screening", "client rejected - interview", "rejected - other", "cancelled", "interview", "topcoder-rejected", "applied", "rejected-pre-screen", "skills-test", "phone-screen", "job-closed", "offered"]
4011+
description: "The array of job Candidates status"
39994012
JobCandidateRequestBody:
40004013
required:
40014014
- jobId

src/controllers/JobCandidateController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Controller for JobCandidate endpoints
33
*/
44
const HttpStatus = require('http-status-codes')
5+
const _ = require('lodash')
56
const service = require('../services/JobCandidateService')
67
const helper = require('../common/helper')
78

@@ -57,7 +58,8 @@ async function deleteJobCandidate (req, res) {
5758
* @param res the response
5859
*/
5960
async function searchJobCandidates (req, res) {
60-
const result = await service.searchJobCandidates(req.authUser, req.query)
61+
const query = { ...req.query, statuses: _.get(req, 'body.statuses', []) }
62+
const result = await service.searchJobCandidates(req.authUser, query)
6163
helper.setResHeaders(req, res, result)
6264
res.send(result.result)
6365
}

src/services/JobCandidateService.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ async function searchJobCandidates (currentUser, criteria) {
283283
}
284284
})
285285
})
286+
287+
// if criteria contains statuses, filter statuses with this value
288+
if (criteria.statuses && criteria.statuses.length > 0) {
289+
esQuery.body.query.bool.filter.push({
290+
terms: {
291+
status: criteria.statuses
292+
}
293+
})
294+
}
286295
logger.debug({ component: 'JobCandidateService', context: 'searchJobCandidates', message: `Query: ${JSON.stringify(esQuery)}` })
287296

288297
const { body } = await esClient.search(esQuery)
@@ -301,10 +310,13 @@ async function searchJobCandidates (currentUser, criteria) {
301310
logger.logFullError(err, { component: 'JobCandidateService', context: 'searchJobCandidates' })
302311
}
303312
logger.info({ component: 'JobCandidateService', context: 'searchJobCandidates', message: 'fallback to DB query' })
304-
const filter = {}
313+
const filter = { [Op.and]: [] }
305314
_.each(_.pick(criteria, ['jobId', 'userId', 'status', 'externalId']), (value, key) => {
306315
filter[Op.and].push({ [key]: value })
307316
})
317+
if (criteria.statuses && criteria.statuses.length > 0) {
318+
filter[Op.and].push({ status: criteria.statuses })
319+
}
308320

309321
// include interviews if user has permission
310322
const include = []
@@ -340,6 +352,7 @@ searchJobCandidates.schema = Joi.object().keys({
340352
jobId: Joi.string().uuid(),
341353
userId: Joi.string().uuid(),
342354
status: Joi.jobCandidateStatus(),
355+
statuses: Joi.array().items(Joi.jobCandidateStatus()),
343356
externalId: Joi.string()
344357
}).required()
345358
}).required()

0 commit comments

Comments
 (0)