Skip to content

Commit b91c7fe

Browse files
Blanca Rosasjaolanlo
authored andcommitted
fix: removing redundant code
1 parent d883f76 commit b91c7fe

3 files changed

Lines changed: 29 additions & 40 deletions

File tree

src/data/postgres/tables/profileProxyConfigs.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ export class ProfileProxyConfigsTable implements IProfileProxyConfigsTable {
6868
)
6969
)
7070

71-
if (proxyProfilesQueryResults?.rowCount) {
72-
if (proxyProfilesQueryResults.rowCount > 0) {
73-
return true
74-
}
71+
if ((proxyProfilesQueryResults?.rowCount ?? 0) > 0) {
72+
return true
7573
}
7674
} catch (error) {
7775
if (error.code === PostgresErr.C23_FOREIGN_KEY_VIOLATION) {
@@ -96,10 +94,8 @@ export class ProfileProxyConfigsTable implements IProfileProxyConfigsTable {
9694
[configName, tenantId]
9795
)
9896

99-
if (deleteProfileWifiResults?.rowCount) {
100-
if (deleteProfileWifiResults.rowCount > 0) {
101-
return true
102-
}
97+
if ((deleteProfileWifiResults?.rowCount ?? 0) > 0) {
98+
return true
10399
}
104100

105101
return false

src/data/postgres/tables/profiles.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,13 @@ export class ProfilesTable implements IProfilesTable {
270270
}
271271
}
272272

273-
if (amtConfig.proxyConfigs) {
274-
if (amtConfig.proxyConfigs?.length > 0) {
275-
await this.db.profileProxyConfigs.createProfileProxyConfigs(
276-
amtConfig.proxyConfigs,
277-
amtConfig.profileName,
278-
amtConfig.tenantId
279-
)
280-
}
273+
const proxyConfigs = amtConfig?.proxyConfigs ?? []
274+
if (proxyConfigs.length > 0) {
275+
await this.db.profileProxyConfigs.createProfileProxyConfigs(
276+
proxyConfigs,
277+
amtConfig.profileName,
278+
amtConfig.tenantId
279+
)
281280
}
282281

283282
return await this.getByName(amtConfig.profileName, amtConfig.tenantId)
@@ -348,9 +347,10 @@ export class ProfilesTable implements IProfilesTable {
348347
amtConfig.tenantId
349348
)
350349
}
351-
if (amtConfig.proxyConfigs && amtConfig.proxyConfigs?.length > 0) {
350+
const proxyConfigs = amtConfig?.proxyConfigs ?? []
351+
if (proxyConfigs.length > 0) {
352352
await this.db.profileProxyConfigs.createProfileProxyConfigs(
353-
amtConfig.proxyConfigs,
353+
proxyConfigs,
354354
amtConfig.profileName,
355355
amtConfig.tenantId
356356
)

src/data/postgres/tables/proxyConfigs.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
4141
[tenantId]
4242
)
4343
let count = 0
44-
if (result != null && result.rows?.length > 0) {
44+
if (result?.rows?.length > 0) {
4545
count = Number(result.rows[0].total_count)
4646
}
4747
return count
@@ -94,11 +94,10 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
9494
[accessInfo, tenantId]
9595
)
9696

97-
if (results?.rowCount) {
98-
if (results.rowCount > 0) {
99-
return results.rows[0]
100-
}
97+
if ((results?.rowCount ?? 0) > 0) {
98+
return results.rows[0]
10199
}
100+
102101
return null
103102
}
104103

@@ -116,11 +115,10 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
116115
[accessInfo, tenantId]
117116
)
118117

119-
if (results?.rowCount) {
120-
if (results.rowCount > 0) {
121-
return true
122-
}
118+
if ((results?.rowCount ?? 0) > 0) {
119+
return true
123120
}
121+
124122
return false
125123
}
126124

@@ -137,10 +135,8 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
137135
WHERE access_info = $1 and tenant_id = $2`,
138136
[accessInfo, tenantId]
139137
)
140-
if (profiles?.rowCount) {
141-
if (profiles.rowCount > 0) {
142-
throw new RPSError(NETWORK_CONFIG_DELETION_FAILED_CONSTRAINT('Proxy', accessInfo), 'Foreign key violation')
143-
}
138+
if ((profiles?.rowCount ?? 0) > 0) {
139+
throw new RPSError(NETWORK_CONFIG_DELETION_FAILED_CONSTRAINT('Proxy', accessInfo), 'Foreign key violation')
144140
}
145141
try {
146142
const results = await this.db.query(
@@ -185,11 +181,10 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
185181
proxyConfig.tenantId
186182
]
187183
)
188-
if (results?.rowCount) {
189-
if (results.rowCount > 0) {
190-
const config = await this.getByName(proxyConfig.accessInfo, proxyConfig.tenantId)
191-
return config
192-
}
184+
185+
if ((results?.rowCount ?? 0) > 0) {
186+
const config = await this.getByName(proxyConfig.accessInfo, proxyConfig.tenantId)
187+
return config
193188
}
194189
} catch (error) {
195190
if (error.code === PostgresErr.C23_UNIQUE_VIOLATION) {
@@ -227,10 +222,8 @@ export class ProxyConfigsTable implements IProxyConfigsTable {
227222
)
228223

229224
latestItem = await this.getByName(proxyConfig.accessInfo, proxyConfig.tenantId)
230-
if (results?.rowCount) {
231-
if (results.rowCount > 0) {
232-
return latestItem
233-
}
225+
if ((results?.rowCount ?? 0) > 0) {
226+
return latestItem
234227
}
235228
} catch (error) {
236229
throw new RPSError(NETWORK_CONFIG_ERROR('Proxy', proxyConfig.accessInfo))

0 commit comments

Comments
 (0)