Skip to content

Commit 31c0d83

Browse files
authored
Fix lfxMembership filter in organization query (#2814)
1 parent 11840a7 commit 31c0d83

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

backend/src/database/repositories/organizationRepository.ts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -316,25 +316,6 @@ class OrganizationRepository {
316316
}
317317
}
318318

319-
static findLfxMembershipInFilters(filter: any): any {
320-
if (!filter) return null
321-
322-
if (filter.lfxMembership) {
323-
return filter.lfxMembership
324-
}
325-
326-
if (Array.isArray(filter.and)) {
327-
for (const subFilter of filter.and) {
328-
const result = OrganizationRepository.findLfxMembershipInFilters(subFilter)
329-
if (result) {
330-
return result
331-
}
332-
}
333-
}
334-
335-
return null
336-
}
337-
338319
static convertOrgAttributesForDisplay(attributes: IDbOrgAttribute[]) {
339320
return attributes.reduce((acc, a) => {
340321
if (!acc[a.name]) {
@@ -1615,7 +1596,7 @@ class OrganizationRepository {
16151596
const withAggregates = include.aggregates
16161597

16171598
// look for lfxMembership filter
1618-
const lfxMembershipFilter = OrganizationRepository.findLfxMembershipInFilters(filter)
1599+
const lfxMembershipFilter = filter.and?.find((f) => f.lfxMembership)?.lfxMembership
16191600
let lfxMembershipFilterWhereClause = ''
16201601

16211602
if (lfxMembershipFilter) {
@@ -1627,8 +1608,14 @@ class OrganizationRepository {
16271608
}
16281609

16291610
// remove lfxMembership filter from obj since filterParser doesn't support it
1630-
filter.and = filter.and.filter((f) => !f.and?.some((subF) => subF.lfxMembership))
1611+
filter.and = filter.and.filter((f) => !f.lfxMembership)
1612+
1613+
// handle edge case where filter.and is empty
1614+
if (filter.and.length === 0) {
1615+
delete filter.and
1616+
}
16311617
}
1618+
16321619
if (segmentId) {
16331620
const segment = (await findSegmentById(optionsQx(options), segmentId)) as any
16341621

0 commit comments

Comments
 (0)