Skip to content

Commit d4f986f

Browse files
add skill Ids in the body
1 parent 35c1f85 commit d4f986f

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/controllers/JobController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async function deleteJob (req, res) {
5858
* @param res the response
5959
*/
6060
async function searchJobs (req, res) {
61-
const query = { ...req.query, jobIds: _.get(req, 'body.jobIds', []) }
61+
const query = { ...req.query, jobIds: _.get(req, 'body.jobIds', []), bodySkills: _.get(req, 'body.bodySkills', []) }
6262
const result = await service.searchJobs(req.authUser, query)
6363
helper.setResHeaders(req, res, result)
6464
res.send(result.result)

src/services/JobService.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,15 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
520520
}
521521
})
522522
}
523+
console.log(criteria.bodySkills)
524+
// if critera contains bodySkills, filter skills with this value
525+
if (criteria.bodySkills && criteria.bodySkills.length > 0) {
526+
esQuery.body.query.bool.filter.push({
527+
terms: {
528+
skills: criteria.bodySkills
529+
}
530+
})
531+
}
523532
logger.debug({ component: 'JobService', context: 'searchJobs', message: `Query: ${JSON.stringify(esQuery)}` })
524533

525534
const { body } = await esClient.search(esQuery)
@@ -566,9 +575,32 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
566575
[Op.like]: `%${criteria.title}%`
567576
}
568577
}
569-
if (criteria.skill) {
570-
filter.skills = {
571-
[Op.contains]: [criteria.skill]
578+
if (criteria.skill || (criteria.bodySkills && criteria.bodySkills.length > 0)) {
579+
const skill = criteria.skill
580+
const bodySkills = criteria.bodySkills
581+
if (skill && bodySkills && bodySkills.length > 0) {
582+
filter.skills = {
583+
[Op.and]: [
584+
{
585+
[Op.contains]: [criteria.skill]
586+
},
587+
{
588+
[Op.or]: _.map(bodySkills, (item) => {
589+
return { [Op.contains]: [item] }
590+
})
591+
}
592+
]
593+
}
594+
} else if (skill) {
595+
filter.skills = {
596+
[Op.contains]: [criteria.skill]
597+
}
598+
} else if (bodySkills && bodySkills > 0) {
599+
filter.skills = {
600+
[Op.or]: _.map(bodySkills, (item) => {
601+
return { [Op.contains]: [item] }
602+
})
603+
}
572604
}
573605
}
574606
if (criteria.role) {
@@ -631,6 +663,7 @@ searchJobs.schema = Joi.object().keys({
631663
status: Joi.jobStatus(),
632664
projectIds: Joi.array().items(Joi.number().integer()).single(),
633665
jobIds: Joi.array().items(Joi.string().uuid()),
666+
bodySkills: Joi.array().items(Joi.string().uuid()),
634667
minSalary: Joi.number().integer(),
635668
maxSalary: Joi.number().integer()
636669
}).required(),

0 commit comments

Comments
 (0)