@@ -231,7 +231,11 @@ createJob.schema = Joi.object()
231
231
jobLocation : Joi . stringAllowEmpty ( ) . allow ( null ) ,
232
232
jobTimezone : Joi . stringAllowEmpty ( ) . allow ( null ) ,
233
233
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 ( '' )
235
239
} )
236
240
. required ( ) ,
237
241
onTeamCreating : Joi . boolean ( ) . default ( false )
@@ -327,7 +331,11 @@ partiallyUpdateJob.schema = Joi.object()
327
331
jobLocation : Joi . stringAllowEmpty ( ) . allow ( null ) ,
328
332
jobTimezone : Joi . stringAllowEmpty ( ) . allow ( null ) ,
329
333
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 )
331
339
} )
332
340
. required ( )
333
341
} )
@@ -367,7 +375,11 @@ fullyUpdateJob.schema = Joi.object().keys({
367
375
jobLocation : Joi . stringAllowEmpty ( ) . allow ( null ) ,
368
376
jobTimezone : Joi . stringAllowEmpty ( ) . allow ( null ) ,
369
377
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 )
371
383
} ) . required ( )
372
384
} ) . required ( )
373
385
@@ -444,7 +456,8 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
444
456
query : {
445
457
bool : {
446
458
must : [ ] ,
447
- filter : [ ]
459
+ filter : [ ] ,
460
+ should : [ ]
448
461
}
449
462
} ,
450
463
from : ( page - 1 ) * perPage ,
@@ -465,7 +478,9 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
465
478
'rateType' ,
466
479
'workload' ,
467
480
'title' ,
468
- 'status'
481
+ 'status' ,
482
+ 'minSalary' ,
483
+ 'maxSalary'
469
484
] ) , ( value , key ) => {
470
485
let must
471
486
if ( key === 'description' || key === 'title' ) {
@@ -482,6 +497,15 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
482
497
[ `${ key } s` ] : [ value ]
483
498
}
484
499
}
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
+ }
485
509
} else {
486
510
must = {
487
511
term : {
@@ -493,6 +517,27 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
493
517
}
494
518
esQuery . body . query . bool . must . push ( must )
495
519
} )
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
+ }
496
541
// If criteria contains projectIds, filter projectId with this value
497
542
if ( criteria . projectIds ) {
498
543
esQuery . body . query . bool . filter . push ( {
@@ -509,6 +554,14 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
509
554
}
510
555
} )
511
556
}
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
+ }
512
565
logger . debug ( { component : 'JobService' , context : 'searchJobs' , message : `Query: ${ JSON . stringify ( esQuery ) } ` } )
513
566
514
567
const { body } = await esClient . search ( esQuery )
@@ -555,9 +608,37 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
555
608
[ Op . like ] : `%${ criteria . title } %`
556
609
}
557
610
}
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
+ }
561
642
}
562
643
}
563
644
if ( criteria . role ) {
@@ -568,6 +649,16 @@ async function searchJobs (currentUser, criteria, options = { returnAll: false }
568
649
if ( criteria . jobIds && criteria . jobIds . length > 0 ) {
569
650
filter [ Op . and ] . push ( { id : criteria . jobIds } )
570
651
}
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
+ }
571
662
const jobs = await Job . findAll ( {
572
663
where : filter ,
573
664
offset : ( ( page - 1 ) * perPage ) ,
@@ -594,7 +685,7 @@ searchJobs.schema = Joi.object().keys({
594
685
criteria : Joi . object ( ) . keys ( {
595
686
page : Joi . number ( ) . integer ( ) ,
596
687
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' ) ,
598
689
sortOrder : Joi . string ( ) . valid ( 'desc' , 'asc' ) ,
599
690
projectId : Joi . number ( ) . integer ( ) ,
600
691
externalId : Joi . string ( ) ,
@@ -609,7 +700,11 @@ searchJobs.schema = Joi.object().keys({
609
700
workload : Joi . workload ( ) ,
610
701
status : Joi . jobStatus ( ) ,
611
702
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 ( )
613
708
} ) . required ( ) ,
614
709
options : Joi . object ( )
615
710
} ) . required ( )
0 commit comments