@@ -556,8 +556,8 @@ async function searchResourceBookings (currentUser, criteria, options = { return
556
556
const { body } = await esClient . search ( esQuery )
557
557
const resourceBookings = _ . map ( body . hits . hits , '_source' )
558
558
// ESClient will return ResourceBookings with it's all nested WorkPeriods
559
- // We re-apply WorkPeriod filters
560
- _ . each ( workPeriodFilters , ( value , key ) => {
559
+ // We re-apply WorkPeriod filters except userHandle because all WPs share same userHandle
560
+ _ . each ( _ . omit ( workPeriodFilters , 'workPeriods.userHandle' ) , ( value , key ) => {
561
561
key = key . split ( '.' ) [ 1 ]
562
562
_ . each ( resourceBookings , r => {
563
563
r . workPeriods = _ . filter ( r . workPeriods , { [ key ] : value } )
@@ -608,11 +608,16 @@ async function searchResourceBookings (currentUser, criteria, options = { return
608
608
queryCriteria . include [ 0 ] . attributes = { exclude : _ . map ( queryOpt . excludeWP , f => _ . split ( f , '.' ) [ 1 ] ) }
609
609
}
610
610
// Apply WorkPeriod filters
611
- _ . each ( _ . pick ( criteria , [ 'workPeriods.startDate' , 'workPeriods.endDate' , 'workPeriods.userHandle' , 'workPeriods. paymentStatus'] ) , ( value , key ) => {
611
+ _ . each ( _ . pick ( criteria , [ 'workPeriods.startDate' , 'workPeriods.endDate' , 'workPeriods.paymentStatus' ] ) , ( value , key ) => {
612
612
key = key . split ( '.' ) [ 1 ]
613
613
queryCriteria . include [ 0 ] . where [ Op . and ] . push ( { [ key ] : value } )
614
- queryCriteria . include [ 0 ] . required = true
615
614
} )
615
+ if ( criteria [ 'workPeriods.userHandle' ] ) {
616
+ queryCriteria . include [ 0 ] . where [ Op . and ] . push ( { userHandle : { [ Op . iLike ] : criteria [ 'workPeriods.userHandle' ] } } )
617
+ }
618
+ if ( queryCriteria . include [ 0 ] . where [ Op . and ] . length > 0 ) {
619
+ queryCriteria . include [ 0 ] . required = true
620
+ }
616
621
}
617
622
// Apply sorting criteria
618
623
if ( ! queryOpt . sortByWP ) {
0 commit comments