Skip to content

Commit 0eef869

Browse files
committed
Make skill matching case-insensitive in getRoleBySkills
1 parent 0361dff commit 0eef869

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/services/TeamService.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const errors = require('../common/errors')
1313
const JobService = require('./JobService')
1414
const ResourceBookingService = require('./ResourceBookingService')
1515
const HttpStatus = require('http-status-codes')
16-
const { Op } = require('sequelize')
16+
const { Op, where, fn, col } = require('sequelize')
1717
const models = require('../models')
1818
const stopWords = require('../../data/stopWords.json')
1919
const { getAuditM2Muser } = require('../common/helper')
@@ -799,17 +799,30 @@ roleSearchRequest.schema = Joi.object()
799799
* @returns {Role} the best matching Role
800800
*/
801801
async function getRoleBySkills (skills) {
802+
// Case-insensitive search for roles matching any of the given skills
802803
const lowerCaseSkills = skills.map(skill => skill.toLowerCase())
803-
// find all roles which includes any of the given skills
804804
const queryCriteria = {
805-
where: { listOfSkills: { [Op.overlap]: lowerCaseSkills } },
805+
where: where(
806+
fn(
807+
'string_to_array',
808+
fn(
809+
'lower',
810+
fn(
811+
'array_to_string',
812+
col('list_of_skills'),
813+
','
814+
)
815+
),
816+
','
817+
),
818+
{[Op.overlap]: lowerCaseSkills }),
806819
raw: true
807820
}
808821
const roles = await Role.findAll(queryCriteria)
809822
if (roles.length > 0) {
810823
let result = _.each(roles, role => {
811-
// calculate each found roles matching rate
812-
role.skillsMatch = _.intersection(role.listOfSkills, lowerCaseSkills).length / skills.length
824+
// calculate each found roles matching rate (must again be made case-insensitive)
825+
role.skillsMatch = _.intersection(role.listOfSkills.map(skill => skill.toLowerCase()), lowerCaseSkills).length / skills.length
813826
// each role can have multiple rates, get the maximum of global rates
814827
role.maxGlobal = _.maxBy(role.rates, 'global').global
815828
})

0 commit comments

Comments
 (0)