Skip to content

Commit 4cfd154

Browse files
authored
Merge pull request #298 from eisbilir/fix/rb-search-issue-01
fix: RB search case insensitive
2 parents 38c8d33 + 86fe56f commit 4cfd154

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/services/ResourceBookingService.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,8 @@ async function searchResourceBookings (currentUser, criteria, options = { return
556556
const { body } = await esClient.search(esQuery)
557557
const resourceBookings = _.map(body.hits.hits, '_source')
558558
// 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) => {
561561
key = key.split('.')[1]
562562
_.each(resourceBookings, r => {
563563
r.workPeriods = _.filter(r.workPeriods, { [key]: value })
@@ -608,11 +608,16 @@ async function searchResourceBookings (currentUser, criteria, options = { return
608608
queryCriteria.include[0].attributes = { exclude: _.map(queryOpt.excludeWP, f => _.split(f, '.')[1]) }
609609
}
610610
// 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) => {
612612
key = key.split('.')[1]
613613
queryCriteria.include[0].where[Op.and].push({ [key]: value })
614-
queryCriteria.include[0].required = true
615614
})
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+
}
616621
}
617622
// Apply sorting criteria
618623
if (!queryOpt.sortByWP) {

0 commit comments

Comments
 (0)