Skip to content

Commit 7f3691c

Browse files
committed
fix: semplify the solution
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 7954b62 commit 7f3691c

3 files changed

Lines changed: 16 additions & 26 deletions

File tree

backend/src/database/repositories/organizationRepository.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,25 +1296,6 @@ 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-
13181299
static async findAndCountAll(
13191300
{
13201301
countOnly = false,
@@ -1335,6 +1316,7 @@ class OrganizationRepository {
13351316
limit = 20,
13361317
offset = 0,
13371318
orderBy = undefined,
1319+
search = undefined as string | undefined,
13381320
segmentId = undefined,
13391321
},
13401322
options: IRepositoryOptions,
@@ -1351,6 +1333,7 @@ class OrganizationRepository {
13511333
limit,
13521334
offset,
13531335
orderBy,
1336+
search,
13541337
segmentId,
13551338
})
13561339

@@ -1364,6 +1347,7 @@ class OrganizationRepository {
13641347
cacheKey,
13651348
{
13661349
filter,
1350+
search,
13671351
limit,
13681352
offset,
13691353
orderBy,
@@ -1385,6 +1369,7 @@ class OrganizationRepository {
13851369
cacheKey,
13861370
{
13871371
filter,
1372+
search,
13881373
segmentId,
13891374
include,
13901375
},
@@ -1405,6 +1390,7 @@ class OrganizationRepository {
14051390
cacheKey,
14061391
{
14071392
filter,
1393+
search,
14081394
limit,
14091395
offset,
14101396
orderBy,
@@ -1422,6 +1408,7 @@ class OrganizationRepository {
14221408
cacheKey: string,
14231409
{
14241410
filter = {} as any,
1411+
search = undefined as string | undefined,
14251412
limit = 20,
14261413
offset = 0,
14271414
orderBy = undefined,
@@ -1447,10 +1434,6 @@ class OrganizationRepository {
14471434

14481435
const withAggregates = include.aggregates
14491436

1450-
const { searchTerm, updatedFilter: filterWithoutSearch } =
1451-
OrganizationRepository.handleSearchFilter(filter)
1452-
filter = filterWithoutSearch
1453-
14541437
const { lfxMembershipFilter, updatedfilter } =
14551438
OrganizationRepository.handleLfxMembershipFilter(filter)
14561439
filter = updatedfilter // updated filter without lfxMembershipFilter
@@ -1489,8 +1472,8 @@ class OrganizationRepository {
14891472
}
14901473

14911474
let searchWhereClause = ''
1492-
if (searchTerm) {
1493-
params.searchTerm = `%${searchTerm}%`
1475+
if (search) {
1476+
params.searchTerm = `%${search}%`
14941477
searchWhereClause = `AND o."displayName" ILIKE $(searchTerm)`
14951478
}
14961479

@@ -1679,6 +1662,7 @@ class OrganizationRepository {
16791662
params: {
16801663
// TODO: REMOVE this any
16811664
filter?: any
1665+
search?: string
16821666
limit: number
16831667
offset: number
16841668
orderBy?: string
@@ -1701,6 +1685,7 @@ class OrganizationRepository {
17011685
cacheKey: string,
17021686
params: {
17031687
filter?: any
1688+
search?: string
17041689
segmentId?: string
17051690
include: any
17061691
},

backend/src/database/repositories/organizationsQueryCache.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class OrganizationQueryCache {
3838
limit: number
3939
offset: number
4040
orderBy?: string
41+
search?: string
4142
segmentId?: string
4243
}): string {
4344
const cleanParams = Object.fromEntries(
@@ -49,6 +50,7 @@ export class OrganizationQueryCache {
4950
limit: params.limit,
5051
offset: params.offset,
5152
orderBy: params.orderBy,
53+
search: params.search,
5254
segmentId: params.segmentId,
5355
}).filter(([, value]) => value !== null && value !== undefined),
5456
)

backend/src/services/organizationService.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,10 +1163,13 @@ export default class OrganizationService extends LoggerBase {
11631163
}
11641164

11651165
async query(data) {
1166-
const { filter, orderBy, limit, offset, segments } = data
1166+
const { filter: rawFilter, orderBy, limit, offset, segments } = data
1167+
const { search, ...filter } = rawFilter ?? {}
1168+
const searchTerm = typeof search === 'string' && search.trim() ? search.trim() : undefined
11671169
return OrganizationRepository.findAndCountAll(
11681170
{
11691171
filter,
1172+
search: searchTerm,
11701173
orderBy,
11711174
limit,
11721175
offset,

0 commit comments

Comments
 (0)