@@ -231,7 +231,11 @@ createJob.schema = Joi.object()
231231 jobLocation : Joi . stringAllowEmpty ( ) . allow ( null ) ,
232232 jobTimezone : Joi . stringAllowEmpty ( ) . allow ( null ) ,
233233 currency : Joi . stringAllowEmpty ( ) . allow ( null ) ,
234- roleIds : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) . required ( ) )
234+ roleIds : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) . required ( ) ) ,
235+ showInHotList : Joi . boolean ( ) . default ( false ) ,
236+ featured : Joi . boolean ( ) . default ( false ) ,
237+ hotListExcerpt : Joi . stringAllowEmpty ( ) . default ( '' ) ,
238+ jobTag : Joi . jobTag ( ) . default ( '' )
235239 } )
236240 . required ( ) ,
237241 onTeamCreating : Joi . boolean ( ) . default ( false )
@@ -327,7 +331,11 @@ partiallyUpdateJob.schema = Joi.object()
327331 jobLocation : Joi . stringAllowEmpty ( ) . allow ( null ) ,
328332 jobTimezone : Joi . stringAllowEmpty ( ) . allow ( null ) ,
329333 currency : Joi . stringAllowEmpty ( ) . allow ( null ) ,
330- roleIds : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) . required ( ) ) . allow ( null )
334+ roleIds : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) . required ( ) ) . allow ( null ) ,
335+ showInHotList : Joi . boolean ( ) . default ( false ) ,
336+ featured : Joi . boolean ( ) . default ( false ) ,
337+ hotListExcerpt : Joi . stringAllowEmpty ( ) . default ( '' ) . allow ( null ) ,
338+ jobTag : Joi . jobTag ( ) . default ( '' ) . allow ( null )
331339 } )
332340 . required ( )
333341 } )
@@ -367,7 +375,11 @@ fullyUpdateJob.schema = Joi.object().keys({
367375 jobLocation : Joi . stringAllowEmpty ( ) . allow ( null ) ,
368376 jobTimezone : Joi . stringAllowEmpty ( ) . allow ( null ) ,
369377 currency : Joi . stringAllowEmpty ( ) . allow ( null ) ,
370- roleIds : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) . required ( ) ) . default ( null )
378+ roleIds : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) . required ( ) ) . default ( null ) ,
379+ showInHotList : Joi . boolean ( ) . default ( false ) ,
380+ featured : Joi . boolean ( ) . default ( false ) ,
381+ hotListExcerpt : Joi . stringAllowEmpty ( ) . default ( '' ) . allow ( null ) ,
382+ jobTag : Joi . jobTag ( ) . default ( '' ) . allow ( null )
371383 } ) . required ( )
372384} ) . required ( )
373385
@@ -444,7 +456,8 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
444456 query : {
445457 bool : {
446458 must : [ ] ,
447- filter : [ ]
459+ filter : [ ] ,
460+ should : [ ]
448461 }
449462 } ,
450463 from : ( page - 1 ) * perPage ,
@@ -465,7 +478,9 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
465478 'rateType' ,
466479 'workload' ,
467480 'title' ,
468- 'status'
481+ 'status' ,
482+ 'minSalary' ,
483+ 'maxSalary'
469484 ] ) , ( value , key ) => {
470485 let must
471486 if ( key === 'description' || key === 'title' ) {
@@ -482,6 +497,15 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
482497 [ `${ key } s` ] : [ value ]
483498 }
484499 }
500+ } else if ( key === 'minSalary' || key === 'maxSalary' ) {
501+ const salaryOp = key === 'minSalary' ? 'gte' : 'lte'
502+ must = {
503+ range : {
504+ [ key ] : {
505+ [ salaryOp ] : value
506+ }
507+ }
508+ }
485509 } else {
486510 must = {
487511 term : {
@@ -493,6 +517,27 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
493517 }
494518 esQuery . body . query . bool . must . push ( must )
495519 } )
520+ // If criteria contains jobLocation, filter jobLocation with this value
521+ if ( criteria . jobLocation ) {
522+ // filter out null value
523+ esQuery . body . query . bool . should . push ( {
524+ bool : {
525+ must : [
526+ {
527+ exists : {
528+ field : 'jobLocation'
529+ }
530+ }
531+ ]
532+ }
533+ } )
534+ // filter the jobLocation
535+ esQuery . body . query . bool . should . push ( {
536+ term : {
537+ jobLocation : criteria . jobLocation
538+ }
539+ } )
540+ }
496541 // If criteria contains projectIds, filter projectId with this value
497542 if ( criteria . projectIds ) {
498543 esQuery . body . query . bool . filter . push ( {
@@ -509,6 +554,14 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
509554 }
510555 } )
511556 }
557+ // if critera contains bodySkills, filter skills with this value
558+ if ( criteria . bodySkills && criteria . bodySkills . length > 0 ) {
559+ esQuery . body . query . bool . filter . push ( {
560+ terms : {
561+ skills : criteria . bodySkills
562+ }
563+ } )
564+ }
512565 logger . debug ( { component : 'JobService' , context : 'searchJobs' , message : `Query: ${ JSON . stringify ( esQuery ) } ` } )
513566
514567 const { body } = await esClient . search ( esQuery )
@@ -555,9 +608,37 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
555608 [ Op . like ] : `%${ criteria . title } %`
556609 }
557610 }
558- if ( criteria . skill ) {
559- filter . skills = {
560- [ Op . contains ] : [ criteria . skill ]
611+ if ( criteria . jobLocation ) {
612+ filter . jobLocation = {
613+ [ Op . like ] : `%${ criteria . jobLocation } %`
614+ }
615+ }
616+ if ( criteria . skill || ( criteria . bodySkills && criteria . bodySkills . length > 0 ) ) {
617+ const skill = criteria . skill
618+ const bodySkills = criteria . bodySkills
619+ if ( skill && bodySkills && bodySkills . length > 0 ) {
620+ filter . skills = {
621+ [ Op . and ] : [
622+ {
623+ [ Op . contains ] : [ criteria . skill ]
624+ } ,
625+ {
626+ [ Op . or ] : _ . map ( bodySkills , ( item ) => {
627+ return { [ Op . contains ] : [ item ] }
628+ } )
629+ }
630+ ]
631+ }
632+ } else if ( skill ) {
633+ filter . skills = {
634+ [ Op . contains ] : [ criteria . skill ]
635+ }
636+ } else if ( bodySkills && bodySkills > 0 ) {
637+ filter . skills = {
638+ [ Op . or ] : _ . map ( bodySkills , ( item ) => {
639+ return { [ Op . contains ] : [ item ] }
640+ } )
641+ }
561642 }
562643 }
563644 if ( criteria . role ) {
@@ -568,6 +649,16 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
568649 if ( criteria . jobIds && criteria . jobIds . length > 0 ) {
569650 filter [ Op . and ] . push ( { id : criteria . jobIds } )
570651 }
652+ if ( criteria . minSalary !== undefined ) {
653+ filter . minSalary = {
654+ [ Op . gte ] : criteria . minSalary
655+ }
656+ }
657+ if ( criteria . maxSalary !== undefined ) {
658+ filter . maxSalary = {
659+ [ Op . lte ] : criteria . maxSalary
660+ }
661+ }
571662 const jobs = await Job . findAll ( {
572663 where : filter ,
573664 offset : ( ( page - 1 ) * perPage ) ,
@@ -594,7 +685,7 @@ searchJobs.schema = Joi.object().keys({
594685 criteria : Joi . object ( ) . keys ( {
595686 page : Joi . number ( ) . integer ( ) ,
596687 perPage : Joi . number ( ) . integer ( ) ,
597- sortBy : Joi . string ( ) . valid ( 'id' , 'createdAt' , 'startDate' , 'rateType' , 'status' ) ,
688+ sortBy : Joi . string ( ) . valid ( 'id' , 'createdAt' , 'updatedAt' , ' startDate', 'rateType' , 'status' ) ,
598689 sortOrder : Joi . string ( ) . valid ( 'desc' , 'asc' ) ,
599690 projectId : Joi . number ( ) . integer ( ) ,
600691 externalId : Joi . string ( ) ,
@@ -609,7 +700,11 @@ searchJobs.schema = Joi.object().keys({
609700 workload : Joi . workload ( ) ,
610701 status : Joi . jobStatus ( ) ,
611702 projectIds : Joi . array ( ) . items ( Joi . number ( ) . integer ( ) ) . single ( ) ,
612- jobIds : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) )
703+ jobIds : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) ) ,
704+ bodySkills : Joi . array ( ) . items ( Joi . string ( ) . uuid ( ) ) ,
705+ minSalary : Joi . number ( ) . integer ( ) ,
706+ maxSalary : Joi . number ( ) . integer ( ) ,
707+ jobLocation : Joi . string ( )
613708 } ) . required ( ) ,
614709 options : Joi . object ( )
615710} ) . required ( )
0 commit comments