@@ -628,29 +628,31 @@ async function searchResourceBookings (currentUser, criteria, options) {
628
628
} )
629
629
}
630
630
} )
631
- const workPeriodPaymentsMust = [ ]
632
- _ . each ( workPeriodPaymentFilters , ( value , key ) => {
633
- workPeriodPaymentsMust . push ( {
634
- term : {
635
- [ key ] : {
636
- value
631
+ const workPeriodPaymentPath = [ ]
632
+ if ( ! _ . isEmpty ( workPeriodPaymentFilters ) ) {
633
+ const workPeriodPaymentsMust = [ ]
634
+ _ . each ( workPeriodPaymentFilters , ( value , key ) => {
635
+ workPeriodPaymentsMust . push ( {
636
+ term : {
637
+ [ key ] : {
638
+ value
639
+ }
637
640
}
641
+ } )
642
+ } )
643
+ workPeriodPaymentPath . push ( {
644
+ nested : {
645
+ path : 'workPeriods.payments' ,
646
+ query : { bool : { must : workPeriodPaymentsMust } }
638
647
}
639
648
} )
640
- } )
649
+ }
641
650
esQuery . body . query . bool . must . push ( {
642
651
nested : {
643
652
path : 'workPeriods' ,
644
653
query : {
645
654
bool : {
646
- must : [ ...workPeriodsMust ,
647
- {
648
- nested : {
649
- path : 'workPeriods.payments' ,
650
- query : { bool : { must : workPeriodPaymentsMust } }
651
- }
652
- }
653
- ]
655
+ must : [ ...workPeriodsMust , ...workPeriodPaymentPath ]
654
656
}
655
657
}
656
658
}
@@ -847,7 +849,7 @@ searchResourceBookings.schema = Joi.object().keys({
847
849
} ) . required ( ) ,
848
850
options : Joi . object ( ) . keys ( {
849
851
returnAll : Joi . boolean ( ) . default ( false ) ,
850
- fromDb : Joi . boolean ( ) . default ( false )
852
+ returnFromDB : Joi . boolean ( ) . default ( false )
851
853
} ) . default ( {
852
854
returnAll : false ,
853
855
returnFromDB : false
0 commit comments