Skip to content

Commit fc44c1c

Browse files
committed
fix: RB search issue
1 parent b74d62f commit fc44c1c

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/services/ResourceBookingService.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -628,29 +628,31 @@ async function searchResourceBookings (currentUser, criteria, options) {
628628
})
629629
}
630630
})
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+
}
637640
}
641+
})
642+
})
643+
workPeriodPaymentPath.push({
644+
nested: {
645+
path: 'workPeriods.payments',
646+
query: { bool: { must: workPeriodPaymentsMust } }
638647
}
639648
})
640-
})
649+
}
641650
esQuery.body.query.bool.must.push({
642651
nested: {
643652
path: 'workPeriods',
644653
query: {
645654
bool: {
646-
must: [...workPeriodsMust,
647-
{
648-
nested: {
649-
path: 'workPeriods.payments',
650-
query: { bool: { must: workPeriodPaymentsMust } }
651-
}
652-
}
653-
]
655+
must: [...workPeriodsMust, ...workPeriodPaymentPath]
654656
}
655657
}
656658
}
@@ -847,7 +849,7 @@ searchResourceBookings.schema = Joi.object().keys({
847849
}).required(),
848850
options: Joi.object().keys({
849851
returnAll: Joi.boolean().default(false),
850-
fromDb: Joi.boolean().default(false)
852+
returnFromDB: Joi.boolean().default(false)
851853
}).default({
852854
returnAll: false,
853855
returnFromDB: false

0 commit comments

Comments
 (0)