Skip to content

fix: role search by skills #374

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 1 commit into from
Jun 23, 2021
Merged
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
9 changes: 4 additions & 5 deletions src/services/TeamService.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ async function roleSearchRequest (currentUser, data) {
if (!_.isUndefined(data.roleId)) {
role = await Role.findById(data.roleId)
role = role.toJSON()
role.skillsMatch = 1;
role.skillsMatch = 1
// if skills is provided then use skills to find role
} else if (!_.isUndefined(data.skills)) {
// validate given skillIds and convert them into skill names
Expand Down Expand Up @@ -799,17 +799,16 @@ roleSearchRequest.schema = Joi.object()
* @returns {Role} the best matching Role
*/
async function getRoleBySkills (skills) {
const lowerCaseSkills = skills.map(skill => skill.toLowerCase())
// find all roles which includes any of the given skills
const queryCriteria = {
where: { listOfSkills: { [Op.overlap]: lowerCaseSkills } },
where: { listOfSkills: { [Op.overlap]: skills } },
raw: true
}
const roles = await Role.findAll(queryCriteria)
if (roles.length > 0) {
let result = _.each(roles, role => {
// calculate each found roles matching rate
role.skillsMatch = _.intersection(role.listOfSkills, lowerCaseSkills).length / skills.length
role.skillsMatch = _.intersection(role.listOfSkills, skills).length / skills.length
// each role can have multiple rates, get the maximum of global rates
role.maxGlobal = _.maxBy(role.rates, 'global').global
})
Expand All @@ -821,7 +820,7 @@ async function getRoleBySkills (skills) {
}
}
// if no matching role found then return Custom role or empty object
return await Role.findOne({ where: { name: { [Op.iLike]: 'Custom' } } }) || {}
return await Role.findOne({ where: { name: { [Op.iLike]: 'Custom' } }, raw: true }) || {}
}

getRoleBySkills.schema = Joi.object()
Expand Down