Skip to content

Commit b1f25db

Browse files
committed
fix: organization query
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent eabfd30 commit b1f25db

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

backend/src/database/repositories/organizationRepository.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,25 @@ class OrganizationRepository {
12961296
return { lfxMembershipFilter, updatedfilter }
12971297
}
12981298

1299+
private static handleSearchFilter(filter: any): {
1300+
searchTerm: string | null
1301+
updatedFilter: any
1302+
} {
1303+
if (!filter || typeof filter !== 'object') {
1304+
return { searchTerm: null, updatedFilter: filter }
1305+
}
1306+
1307+
const updatedFilter = { ...filter }
1308+
let searchTerm: string | null = null
1309+
1310+
if (typeof updatedFilter.search === 'string' && updatedFilter.search.trim()) {
1311+
searchTerm = updatedFilter.search.trim()
1312+
}
1313+
delete updatedFilter.search
1314+
1315+
return { searchTerm, updatedFilter }
1316+
}
1317+
12991318
static async findAndCountAll(
13001319
{
13011320
countOnly = false,
@@ -1428,6 +1447,10 @@ class OrganizationRepository {
14281447

14291448
const withAggregates = include.aggregates
14301449

1450+
const { searchTerm, updatedFilter: filterWithoutSearch } =
1451+
OrganizationRepository.handleSearchFilter(filter)
1452+
filter = filterWithoutSearch
1453+
14311454
const { lfxMembershipFilter, updatedfilter } =
14321455
OrganizationRepository.handleLfxMembershipFilter(filter)
14331456
filter = updatedfilter // updated filter without lfxMembershipFilter
@@ -1458,13 +1481,19 @@ class OrganizationRepository {
14581481
segmentId = segment.id
14591482
}
14601483

1461-
const params = {
1484+
const params: Record<string, any> = {
14621485
limit,
14631486
offset,
14641487
segmentId,
14651488
tenantId: options.currentTenant.id,
14661489
}
14671490

1491+
let searchWhereClause = ''
1492+
if (searchTerm) {
1493+
params.searchTerm = `%${searchTerm}%`
1494+
searchWhereClause = `AND o."displayName" ILIKE $(searchTerm)`
1495+
}
1496+
14681497
const filterString = RawQueryParser.parseFilters(
14691498
filter,
14701499
OrganizationRepository.QUERY_FILTER_COLUMN_MAP,
@@ -1498,6 +1527,7 @@ class OrganizationRepository {
14981527
WHERE 1=1
14991528
AND o."tenantId" = $(tenantId)
15001529
${lfxMembershipFilterWhereClause}
1530+
${searchWhereClause}
15011531
AND (${filterString})
15021532
`
15031533
const countQuery = createQuery('COUNT(*)')

0 commit comments

Comments
 (0)