@@ -760,7 +760,7 @@ async function roleSearchRequest (currentUser, data) {
760
760
if ( ! _ . isUndefined ( data . roleId ) ) {
761
761
role = await Role . findById ( data . roleId )
762
762
role = role . toJSON ( )
763
- role . skillsMatch = 1 ;
763
+ role . skillsMatch = 1
764
764
// if skills is provided then use skills to find role
765
765
} else if ( ! _ . isUndefined ( data . skills ) ) {
766
766
// validate given skillIds and convert them into skill names
@@ -799,17 +799,16 @@ roleSearchRequest.schema = Joi.object()
799
799
* @returns {Role } the best matching Role
800
800
*/
801
801
async function getRoleBySkills ( skills ) {
802
- const lowerCaseSkills = skills . map ( skill => skill . toLowerCase ( ) )
803
802
// find all roles which includes any of the given skills
804
803
const queryCriteria = {
805
- where : { listOfSkills : { [ Op . overlap ] : lowerCaseSkills } } ,
804
+ where : { listOfSkills : { [ Op . overlap ] : skills } } ,
806
805
raw : true
807
806
}
808
807
const roles = await Role . findAll ( queryCriteria )
809
808
if ( roles . length > 0 ) {
810
809
let result = _ . each ( roles , role => {
811
810
// calculate each found roles matching rate
812
- role . skillsMatch = _ . intersection ( role . listOfSkills , lowerCaseSkills ) . length / skills . length
811
+ role . skillsMatch = _ . intersection ( role . listOfSkills , skills ) . length / skills . length
813
812
// each role can have multiple rates, get the maximum of global rates
814
813
role . maxGlobal = _ . maxBy ( role . rates , 'global' ) . global
815
814
} )
@@ -821,7 +820,7 @@ async function getRoleBySkills (skills) {
821
820
}
822
821
}
823
822
// if no matching role found then return Custom role or empty object
824
- return await Role . findOne ( { where : { name : { [ Op . iLike ] : 'Custom' } } } ) || { }
823
+ return await Role . findOne ( { where : { name : { [ Op . iLike ] : 'Custom' } } , raw : true } ) || { }
825
824
}
826
825
827
826
getRoleBySkills . schema = Joi . object ( )
0 commit comments