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(); return approveAction();
case url.endsWith('/areanames') && method === 'GET': case url.endsWith('/areanames') && method === 'GET':
return getAreaNames(); return getAreaNames();
case url.match(/\/areanames\/\w+$/) && method === 'GET': case url.match(/\/areanames\/\w+/) && method === 'GET':
return getAreaNameByLocation(); return getAreaNameByLocation();
case url.endsWith('/areatypes') && method === 'GET': case url.endsWith('/areatypes') && method === 'GET':
return getAreaTypes(); return getAreaTypes();
case url.match(/\/areatypes\/\w+$/) && method === 'GET': case url.match(/\/areatypes\/\w+/) && method === 'GET':
return getAreaTypeByArea(); return getAreaTypeByArea();
case url.endsWith('/categories') && method === 'GET': case url.endsWith('/categories') && method === 'GET':
return getCategories(); return getCategories();
case url.match(/\/categories\/\w+$/) && method === 'GET': case url.match(/\/categories\/\w+/) && method === 'GET':
return getCategoryByProduct(); return getCategoryByProduct();
case url.endsWith('/genders') && method === 'GET': case url.endsWith('/genders') && method === 'GET':
return getGenders(); return getGenders();
case url.endsWith('/tokens') && method === 'GET': case url.endsWith('/tokens') && method === 'GET':
return getTokens(); return getTokens();
case url.match(/\/tokens\/\w+$/) && method === 'GET': case url.match(/\/tokens\/\w+/) && method === 'GET':
return getTokenBySymbol(); return getTokenBySymbol();
case url.endsWith('/transactiontypes') && method === 'GET': case url.endsWith('/transactiontypes') && method === 'GET':
return getTransactionTypes(); return getTransactionTypes();
@ -1170,10 +1170,16 @@ export class MockBackendInterceptor implements HttpInterceptor {
} }
function getAreaNameByLocation(): Observable<HttpResponse<any>> { function getAreaNameByLocation(): Observable<HttpResponse<any>> {
const keywords = stringFromUrl().split(' ');
for (const keyword of keywords) {
const queriedAreaName: AreaName = areaNames.find((areaName) => const queriedAreaName: AreaName = areaNames.find((areaName) =>
areaName.locations.includes(stringFromUrl()) areaName.locations.includes(keyword)
); );
return ok(queriedAreaName.name || 'other'); if (queriedAreaName) {
return ok(queriedAreaName.name);
}
}
return ok('other');
} }
function getAreaTypes(): Observable<HttpResponse<any>> { function getAreaTypes(): Observable<HttpResponse<any>> {
@ -1182,10 +1188,16 @@ export class MockBackendInterceptor implements HttpInterceptor {
} }
function getAreaTypeByArea(): Observable<HttpResponse<any>> { function getAreaTypeByArea(): Observable<HttpResponse<any>> {
const keywords = stringFromUrl().split(' ');
for (const keyword of keywords) {
const queriedAreaType: AreaType = areaTypes.find((areaType) => const queriedAreaType: AreaType = areaTypes.find((areaType) =>
areaType.area.includes(stringFromUrl()) areaType.area.includes(keyword)
); );
return ok(queriedAreaType.name || 'other'); if (queriedAreaType) {
return ok(queriedAreaType.name);
}
}
return ok('other');
} }
function getCategories(): Observable<HttpResponse<any>> { function getCategories(): Observable<HttpResponse<any>> {
@ -1194,10 +1206,16 @@ export class MockBackendInterceptor implements HttpInterceptor {
} }
function getCategoryByProduct(): Observable<HttpResponse<any>> { function getCategoryByProduct(): Observable<HttpResponse<any>> {
const keywords = stringFromUrl().split(' ');
for (const keyword of keywords) {
const queriedCategory: Category = categories.find((category) => const queriedCategory: Category = categories.find((category) =>
category.products.includes(stringFromUrl()) category.products.includes(keyword)
); );
return ok(queriedCategory.name || 'other'); if (queriedCategory) {
return ok(queriedCategory.name);
}
}
return ok('other');
} }
function getGenders(): Observable<HttpResponse<any>> { function getGenders(): Observable<HttpResponse<any>> {
@ -1209,8 +1227,14 @@ export class MockBackendInterceptor implements HttpInterceptor {
} }
function getTokenBySymbol(): Observable<HttpResponse<any>> { function getTokenBySymbol(): Observable<HttpResponse<any>> {
const queriedToken: Token = tokens.find((token) => token.symbol === stringFromUrl()); const keywords = stringFromUrl().split(' ');
return ok(queriedToken); 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>> { function getTransactionTypes(): Observable<HttpResponse<any>> {

View File

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

View File

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

View File

@ -65,6 +65,9 @@ export class AccountDetailsComponent implements OnInit {
submitted: boolean = false; submitted: boolean = false;
bloxbergLink: string; bloxbergLink: string;
tokenSymbol: string; tokenSymbol: string;
category: string;
area: string;
areaType: string;
constructor( constructor(
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
@ -112,6 +115,27 @@ export class AccountDetailsComponent implements OnInit {
this.account = res; this.account = res;
this.cdr.detectChanges(); this.cdr.detectChanges();
this.loggingService.sendInfoLevelMessage(this.account); 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(' '); const fullName = this.account.vcard?.fn[0].value.split(' ');
this.accountInfoForm.patchValue({ this.accountInfoForm.patchValue({
firstName: fullName[0].split(',')[0], firstName: fullName[0].split(',')[0],
@ -121,26 +145,10 @@ export class AccountDetailsComponent implements OnInit {
type: this.account.type, type: this.account.type,
bio: this.account.products, bio: this.account.products,
gender: this.account.gender, gender: this.account.gender,
businessCategory: businessCategory: this.account.category || this.category || 'other',
this.account.category ||
this.userService.getCategoryByProduct(this.account.products[0]),
userLocation: this.account.location.area_name, userLocation: this.account.location.area_name,
location: location: this.account.location.area || this.area || 'other',
this.account.location.area || locationType: this.account.location.area_type || this.areaType || 'other',
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;
}),
}); });
this.userService this.userService
.getAccountStatus(this.account.vcard?.tel[0].value) .getAccountStatus(this.account.vcard?.tel[0].value)