From cc1621749bdd9fd38f0c8c24ffbc14e38b2cbe2d Mon Sep 17 00:00:00 2001 From: Arno Erpenbeck <88486704+arnoerpenbeck@users.noreply.github.com> Date: Wed, 16 Oct 2024 16:30:34 +0200 Subject: [PATCH] chore: fix some Sonar findings --- src/common/httpClient/testHttpClient.ts | 2 +- src/common/httpClient/testHttpClientHandler.ts | 4 +--- src/fft-api/common/fftApiClientService.ts | 2 +- src/fft-api/facility/fftFacilityService.ts | 16 +++++++--------- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/common/httpClient/testHttpClient.ts b/src/common/httpClient/testHttpClient.ts index c67ee69..16c16a2 100644 --- a/src/common/httpClient/testHttpClient.ts +++ b/src/common/httpClient/testHttpClient.ts @@ -19,7 +19,7 @@ export class TestHttpClient implements BasicHttpClient { const resolvedObj = resolvedHttpRequest.resolveTo; if (resolvedObj) { const httpResult: HttpResult = { - body: resolvedObj as TDto, + body: resolvedObj, statusCode: resolvedHttpRequest.resolveStatusCode ?? 200, }; return Promise.resolve(httpResult); diff --git a/src/common/httpClient/testHttpClientHandler.ts b/src/common/httpClient/testHttpClientHandler.ts index a90a7b4..9b82b7b 100644 --- a/src/common/httpClient/testHttpClientHandler.ts +++ b/src/common/httpClient/testHttpClientHandler.ts @@ -114,9 +114,7 @@ export class TestHttpClientHandler { if (!a || !b) { return false; } - const equal = this.aEntriesPresentInB(a, b, ignoreKeys) && this.aEntriesPresentInB(b, a, ignoreKeys); - // console.log(`${Object.entries(a)} : ${Object.entries(b)} => equal: ${equal}`); - return equal; + return this.aEntriesPresentInB(a, b, ignoreKeys) && this.aEntriesPresentInB(b, a, ignoreKeys); } private aEntriesPresentInB(a: QueryParams, b: QueryParams, ignoreKeys: string[] | undefined) { diff --git a/src/fft-api/common/fftApiClientService.ts b/src/fft-api/common/fftApiClientService.ts index b08a585..9f896ca 100644 --- a/src/fft-api/common/fftApiClientService.ts +++ b/src/fft-api/common/fftApiClientService.ts @@ -76,7 +76,7 @@ export class FftApiClient { retries: method === HttpMethod.GET ? MAX_RETRIES : 0, responseType, }); - return result.body as T; + return result.body; } catch (error) { handleError(error); } diff --git a/src/fft-api/facility/fftFacilityService.ts b/src/fft-api/facility/fftFacilityService.ts index e2d64da..68c6d72 100644 --- a/src/fft-api/facility/fftFacilityService.ts +++ b/src/fft-api/facility/fftFacilityService.ts @@ -31,7 +31,7 @@ export class FftFacilityService { public async getFacilityId(tenantFacilityId: string, relaxed = false): Promise { if (FftFacilityService.facilityCache.has(tenantFacilityId)) { - return FftFacilityService.facilityCache.get(tenantFacilityId) as string; + return FftFacilityService.facilityCache.get(tenantFacilityId); } const strippedFacilities = await this.apiClient.get(this.PATH, { tenantFacilityId }); @@ -46,15 +46,13 @@ export class FftFacilityService { `Did not find exactly 1 facility with tenantFacilityId '${tenantFacilityId}' but ${length}, returning first one with id '${facility.id}'` ); } + } else if (relaxed) { + return undefined; } else { - if (relaxed) { - return undefined; - } else { - console.error(`Did not find facility with tenantFacilityId '${tenantFacilityId}'`); - throw new FftApiError({ - message: `Did not find facility with tenantFacilityId '${tenantFacilityId}'`, - }); - } + console.error(`Did not find facility with tenantFacilityId '${tenantFacilityId}'`); + throw new FftApiError({ + message: `Did not find facility with tenantFacilityId '${tenantFacilityId}'`, + }); } return facility.id;