From 4463065a681da22770c51c57a024f9753a30beb4 Mon Sep 17 00:00:00 2001 From: eisbilir Date: Tue, 22 Jun 2021 22:07:05 +0300 Subject: [PATCH] fix: role search --- src/services/TeamService.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/services/TeamService.js b/src/services/TeamService.js index bc236cf1..99a23888 100644 --- a/src/services/TeamService.js +++ b/src/services/TeamService.js @@ -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 @@ -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 }) @@ -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()