Refactor mapping of curated options from meta.

This commit is contained in:
Spencer Ofwiti 2021-06-16 12:15:38 +03:00
parent 91b50f68f1
commit b72d00a870
4 changed files with 73 additions and 43 deletions

View File

@ -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<HttpResponse<any>> {
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<HttpResponse<any>> {
@ -1182,10 +1188,16 @@ export class MockBackendInterceptor implements HttpInterceptor {
}
function getAreaTypeByArea(): Observable<HttpResponse<any>> {
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<HttpResponse<any>> {
@ -1194,10 +1206,16 @@ export class MockBackendInterceptor implements HttpInterceptor {
}
function getCategoryByProduct(): Observable<HttpResponse<any>> {
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<HttpResponse<any>> {
@ -1209,8 +1227,14 @@ export class MockBackendInterceptor implements HttpInterceptor {
}
function getTokenBySymbol(): Observable<HttpResponse<any>> {
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<HttpResponse<any>> {

View File

@ -23,8 +23,6 @@ export class LocationService {
}
getAreaTypeByArea(area: string): Observable<any> {
return this.httpClient
.get(`${environment.cicMetaUrl}/areatypes/${area.toLowerCase()}`)
.pipe(first());
return this.httpClient.get(`${environment.cicMetaUrl}/areatypes/${area.toLowerCase()}`);
}
}

View File

@ -192,7 +192,7 @@
<mat-label> BUSINESS CATEGORY: </mat-label>
<mat-select
id="businessCategory"
[(value)]="account.category"
[(value)]="category"
formControlName="businessCategory"
[errorStateMatcher]="matcher"
>
@ -229,7 +229,7 @@
<mat-label> LOCATION: </mat-label>
<mat-select
id="location"
[(value)]="account.location.area"
[(value)]="area"
formControlName="location"
[errorStateMatcher]="matcher"
>
@ -248,7 +248,7 @@
<mat-label> LOCATION TYPE: </mat-label>
<mat-select
id="locationType"
[(value)]="account.location.area_type"
[(value)]="areaType"
formControlName="locationType"
[errorStateMatcher]="matcher"
>

View File

@ -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)