@@ -13,7 +13,7 @@ const errors = require('../common/errors')
13
13
const JobService = require ( './JobService' )
14
14
const ResourceBookingService = require ( './ResourceBookingService' )
15
15
const HttpStatus = require ( 'http-status-codes' )
16
- const { Op } = require ( 'sequelize' )
16
+ const { Op, where , fn , col } = require ( 'sequelize' )
17
17
const models = require ( '../models' )
18
18
const stopWords = require ( '../../data/stopWords.json' )
19
19
const { getAuditM2Muser } = require ( '../common/helper' )
@@ -776,11 +776,12 @@ async function roleSearchRequest (currentUser, data) {
776
776
}
777
777
data . roleId = role . id
778
778
// create roleSearchRequest entity with found roleId
779
- const { id : roleSearchRequestId } = await createRoleSearchRequest ( currentUser , data )
779
+ const { id : roleSearchRequestId , jobTitle } = await createRoleSearchRequest ( currentUser , data )
780
+ const entity = jobTitle ? { jobTitle, roleSearchRequestId } : { roleSearchRequestId } ;
780
781
// clean Role
781
782
role = await _cleanRoleDTO ( currentUser , role )
782
783
// return Role
783
- return _ . assign ( role , { roleSearchRequestId } )
784
+ return _ . assign ( role , entity )
784
785
}
785
786
786
787
roleSearchRequest . schema = Joi . object ( )
@@ -789,8 +790,10 @@ roleSearchRequest.schema = Joi.object()
789
790
data : Joi . object ( ) . keys ( {
790
791
roleId : Joi . string ( ) . uuid ( ) ,
791
792
jobDescription : Joi . string ( ) . max ( 255 ) ,
792
- skills : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) . required ( ) )
793
- } ) . required ( ) . min ( 1 )
793
+ skills : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) . required ( ) ) ,
794
+ jobTitle : Joi . string ( ) . max ( 100 ) ,
795
+ previousRoleSearchRequestId : Joi . string ( ) . uuid ( )
796
+ } ) . required ( ) . or ( 'roleId' , 'jobDescription' , 'skills' )
794
797
} ) . required ( )
795
798
796
799
/**
@@ -799,17 +802,30 @@ roleSearchRequest.schema = Joi.object()
799
802
* @returns {Role } the best matching Role
800
803
*/
801
804
async function getRoleBySkills ( skills ) {
805
+ // Case-insensitive search for roles matching any of the given skills
802
806
const lowerCaseSkills = skills . map ( skill => skill . toLowerCase ( ) )
803
- // find all roles which includes any of the given skills
804
807
const queryCriteria = {
805
- where : { listOfSkills : { [ Op . overlap ] : lowerCaseSkills } } ,
808
+ where : where (
809
+ fn (
810
+ 'string_to_array' ,
811
+ fn (
812
+ 'lower' ,
813
+ fn (
814
+ 'array_to_string' ,
815
+ col ( 'list_of_skills' ) ,
816
+ ','
817
+ )
818
+ ) ,
819
+ ','
820
+ ) ,
821
+ { [ Op . overlap ] : lowerCaseSkills } ) ,
806
822
raw : true
807
823
}
808
824
const roles = await Role . findAll ( queryCriteria )
809
825
if ( roles . length > 0 ) {
810
826
let result = _ . each ( roles , role => {
811
- // calculate each found roles matching rate
812
- role . skillsMatch = _ . intersection ( role . listOfSkills , lowerCaseSkills ) . length / skills . length
827
+ // calculate each found roles matching rate (must again be made case-insensitive)
828
+ role . skillsMatch = _ . intersection ( role . listOfSkills . map ( skill => skill . toLowerCase ( ) ) , lowerCaseSkills ) . length / skills . length
813
829
// each role can have multiple rates, get the maximum of global rates
814
830
role . maxGlobal = _ . maxBy ( role . rates , 'global' ) . global
815
831
} )
0 commit comments