diff --git a/src/app/_helpers/mock-backend.ts b/src/app/_helpers/mock-backend.ts index 48d83e5..59c8a12 100644 --- a/src/app/_helpers/mock-backend.ts +++ b/src/app/_helpers/mock-backend.ts @@ -1118,21 +1118,21 @@ export class MockBackendInterceptor implements HttpInterceptor { return approveAction(); case url.endsWith('/areanames') && method === 'GET': return getAreaNames(); - case url.match(/\/areanames\/\w+$/) && method === 'GET': + case url.match(/\/areanames\/\w+/) && method === 'GET': return getAreaNameByLocation(); case url.endsWith('/areatypes') && method === 'GET': return getAreaTypes(); - case url.match(/\/areatypes\/\w+$/) && method === 'GET': + case url.match(/\/areatypes\/\w+/) && method === 'GET': return getAreaTypeByArea(); case url.endsWith('/categories') && method === 'GET': return getCategories(); - case url.match(/\/categories\/\w+$/) && method === 'GET': + case url.match(/\/categories\/\w+/) && method === 'GET': return getCategoryByProduct(); case url.endsWith('/genders') && method === 'GET': return getGenders(); case url.endsWith('/tokens') && method === 'GET': return getTokens(); - case url.match(/\/tokens\/\w+$/) && method === 'GET': + case url.match(/\/tokens\/\w+/) && method === 'GET': return getTokenBySymbol(); case url.endsWith('/transactiontypes') && method === 'GET': return getTransactionTypes(); @@ -1170,10 +1170,16 @@ export class MockBackendInterceptor implements HttpInterceptor { } function getAreaNameByLocation(): Observable> { - const queriedAreaName: AreaName = areaNames.find((areaName) => - areaName.locations.includes(stringFromUrl()) - ); - return ok(queriedAreaName.name || 'other'); + const keywords = stringFromUrl().split(' '); + for (const keyword of keywords) { + const queriedAreaName: AreaName = areaNames.find((areaName) => + areaName.locations.includes(keyword) + ); + if (queriedAreaName) { + return ok(queriedAreaName.name); + } + } + return ok('other'); } function getAreaTypes(): Observable> { @@ -1182,10 +1188,16 @@ export class MockBackendInterceptor implements HttpInterceptor { } function getAreaTypeByArea(): Observable> { - const queriedAreaType: AreaType = areaTypes.find((areaType) => - areaType.area.includes(stringFromUrl()) - ); - return ok(queriedAreaType.name || 'other'); + const keywords = stringFromUrl().split(' '); + for (const keyword of keywords) { + const queriedAreaType: AreaType = areaTypes.find((areaType) => + areaType.area.includes(keyword) + ); + if (queriedAreaType) { + return ok(queriedAreaType.name); + } + } + return ok('other'); } function getCategories(): Observable> { @@ -1194,10 +1206,16 @@ export class MockBackendInterceptor implements HttpInterceptor { } function getCategoryByProduct(): Observable> { - const queriedCategory: Category = categories.find((category) => - category.products.includes(stringFromUrl()) - ); - return ok(queriedCategory.name || 'other'); + const keywords = stringFromUrl().split(' '); + for (const keyword of keywords) { + const queriedCategory: Category = categories.find((category) => + category.products.includes(keyword) + ); + if (queriedCategory) { + return ok(queriedCategory.name); + } + } + return ok('other'); } function getGenders(): Observable> { @@ -1209,8 +1227,14 @@ export class MockBackendInterceptor implements HttpInterceptor { } function getTokenBySymbol(): Observable> { - const queriedToken: Token = tokens.find((token) => token.symbol === stringFromUrl()); - return ok(queriedToken); + const keywords = stringFromUrl().split(' '); + for (const keyword of keywords) { + const queriedToken: Token = tokens.find((token) => token.symbol === keyword); + if (queriedToken) { + return ok(queriedToken.name); + } + } + return ok('other'); } function getTransactionTypes(): Observable> { diff --git a/src/app/_services/location.service.ts b/src/app/_services/location.service.ts index d695f65..2616f02 100644 --- a/src/app/_services/location.service.ts +++ b/src/app/_services/location.service.ts @@ -23,8 +23,6 @@ export class LocationService { } getAreaTypeByArea(area: string): Observable { - return this.httpClient - .get(`${environment.cicMetaUrl}/areatypes/${area.toLowerCase()}`) - .pipe(first()); + return this.httpClient.get(`${environment.cicMetaUrl}/areatypes/${area.toLowerCase()}`); } } diff --git a/src/app/pages/accounts/account-details/account-details.component.html b/src/app/pages/accounts/account-details/account-details.component.html index a886a98..3b48095 100644 --- a/src/app/pages/accounts/account-details/account-details.component.html +++ b/src/app/pages/accounts/account-details/account-details.component.html @@ -192,7 +192,7 @@ BUSINESS CATEGORY: @@ -229,7 +229,7 @@ LOCATION: @@ -248,7 +248,7 @@ LOCATION TYPE: diff --git a/src/app/pages/accounts/account-details/account-details.component.ts b/src/app/pages/accounts/account-details/account-details.component.ts index 9c766be..126f349 100644 --- a/src/app/pages/accounts/account-details/account-details.component.ts +++ b/src/app/pages/accounts/account-details/account-details.component.ts @@ -65,6 +65,9 @@ export class AccountDetailsComponent implements OnInit { submitted: boolean = false; bloxbergLink: string; tokenSymbol: string; + category: string; + area: string; + areaType: string; constructor( private formBuilder: FormBuilder, @@ -112,6 +115,27 @@ export class AccountDetailsComponent implements OnInit { this.account = res; this.cdr.detectChanges(); this.loggingService.sendInfoLevelMessage(this.account); + this.locationService + .getAreaNameByLocation(this.account.location.area_name) + .pipe(first()) + .subscribe((response) => { + this.area = response; + this.cdr.detectChanges(); + this.locationService + .getAreaTypeByArea(this.area) + .pipe(first()) + .subscribe((result) => { + this.areaType = result; + this.cdr.detectChanges(); + }); + }); + this.userService + .getCategoryByProduct(this.account.products[0]) + .pipe(first()) + .subscribe((response) => { + this.category = response; + this.cdr.detectChanges(); + }); const fullName = this.account.vcard?.fn[0].value.split(' '); this.accountInfoForm.patchValue({ firstName: fullName[0].split(',')[0], @@ -121,26 +145,10 @@ export class AccountDetailsComponent implements OnInit { type: this.account.type, bio: this.account.products, gender: this.account.gender, - businessCategory: - this.account.category || - this.userService.getCategoryByProduct(this.account.products[0]), + businessCategory: this.account.category || this.category || 'other', userLocation: this.account.location.area_name, - location: - this.account.location.area || - this.locationService - .getAreaNameByLocation(this.account.location.area_name) - .pipe(first()) - .subscribe((response) => { - return response; - }), - locationType: - this.account.location.area_type || - this.locationService - .getAreaTypeByArea(this.accountInfoFormStub.location.value) - .pipe(first()) - .subscribe((response) => { - return response; - }), + location: this.account.location.area || this.area || 'other', + locationType: this.account.location.area_type || this.areaType || 'other', }); this.userService .getAccountStatus(this.account.vcard?.tel[0].value)