@@ -760,7 +760,7 @@ async function roleSearchRequest (currentUser, data) {
760760 if ( ! _ . isUndefined ( data . roleId ) ) {
761761 role = await Role . findById ( data . roleId )
762762 role = role . toJSON ( )
763- role . skillsMatch = 1 ;
763+ role . skillsMatch = 1
764764 // if skills is provided then use skills to find role
765765 } else if ( ! _ . isUndefined ( data . skills ) ) {
766766 // validate given skillIds and convert them into skill names
@@ -799,17 +799,16 @@ roleSearchRequest.schema = Joi.object()
799799 * @returns {Role } the best matching Role
800800 */
801801async function getRoleBySkills ( skills ) {
802- const lowerCaseSkills = skills . map ( skill => skill . toLowerCase ( ) )
803802 // find all roles which includes any of the given skills
804803 const queryCriteria = {
805- where : { listOfSkills : { [ Op . overlap ] : lowerCaseSkills } } ,
804+ where : { listOfSkills : { [ Op . overlap ] : skills } } ,
806805 raw : true
807806 }
808807 const roles = await Role . findAll ( queryCriteria )
809808 if ( roles . length > 0 ) {
810809 let result = _ . each ( roles , role => {
811810 // 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
813812 // each role can have multiple rates, get the maximum of global rates
814813 role . maxGlobal = _ . maxBy ( role . rates , 'global' ) . global
815814 } )
@@ -821,7 +820,7 @@ async function getRoleBySkills (skills) {
821820 }
822821 }
823822 // 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 } ) || { }
825824}
826825
827826getRoleBySkills . schema = Joi . object ( )
0 commit comments