Add querying of account types, transaction types and genders from meta server.

This commit is contained in:
Spencer Ofwiti 2021-04-28 20:24:25 +03:00
parent ce26380e84
commit e6de26be2c
10 changed files with 76 additions and 37 deletions

View File

@ -230,6 +230,10 @@ const areaTypes = [
} }
]; ];
const accountTypes = ['user', 'cashier', 'vendor', 'tokenagent', 'group'];
const transactionTypes = ['transactions', 'conversions', 'disbursements', 'rewards', 'reclamation'];
const genders = ['male', 'female', 'other'];
@Injectable() @Injectable()
export class MockBackendInterceptor implements HttpInterceptor { export class MockBackendInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
@ -267,6 +271,12 @@ export class MockBackendInterceptor implements HttpInterceptor {
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('/accounttypes') && method === 'GET':
return getAccountTypes();
case url.endsWith('/transactiontypes') && method === 'GET':
return getTransactionTypes();
case url.endsWith('/genders') && method === 'GET':
return getGenders();
default: default:
// pass through any requests not handled above // pass through any requests not handled above
return next.handle(request); return next.handle(request);
@ -330,6 +340,18 @@ export class MockBackendInterceptor implements HttpInterceptor {
return ok(queriedAreaType.name); return ok(queriedAreaType.name);
} }
function getAccountTypes(): Observable<any> {
return ok(accountTypes);
}
function getTransactionTypes(): Observable<any> {
return ok(transactionTypes);
}
function getGenders(): Observable<any> {
return ok(genders);
}
// helper functions // helper functions
function ok(body): Observable<any> { function ok(body): Observable<any> {

View File

@ -209,4 +209,16 @@ export class UserService {
getCategoryByProduct(product: string): Observable<any> { getCategoryByProduct(product: string): Observable<any> {
return this.httpClient.get(`${environment.cicMetaUrl}/categories/${product.toLowerCase()}`); return this.httpClient.get(`${environment.cicMetaUrl}/categories/${product.toLowerCase()}`);
} }
getAccountTypes(): Observable<any> {
return this.httpClient.get(`${environment.cicMetaUrl}/accounttypes`);
}
getTransactionTypes(): Observable<any> {
return this.httpClient.get(`${environment.cicMetaUrl}/transactiontypes`);
}
getGenders(): Observable<any> {
return this.httpClient.get(`${environment.cicMetaUrl}/genders`);
}
} }

View File

@ -78,11 +78,9 @@
<mat-label> ACCOUNT TYPE: </mat-label> <mat-label> ACCOUNT TYPE: </mat-label>
<mat-select id="accountType" [(value)]="account.type" formControlName="type" <mat-select id="accountType" [(value)]="account.type" formControlName="type"
[errorStateMatcher]="matcher"> [errorStateMatcher]="matcher">
<mat-option value="user"> USER </mat-option> <mat-option *ngFor="let accountType of accountTypes" [value]="accountType">
<mat-option value="cashier"> CASHIER </mat-option> {{accountType | uppercase}}
<mat-option value="vendor"> VENDOR </mat-option> </mat-option>
<mat-option value="tokenAgent"> TOKENAGENT </mat-option>
<mat-option value="group"> GROUPACCOUNT </mat-option>
</mat-select> </mat-select>
<mat-error *ngIf="submitted && accountInfoFormStub.type.errors">Type is required.</mat-error> <mat-error *ngIf="submitted && accountInfoFormStub.type.errors">Type is required.</mat-error>
</mat-form-field> </mat-form-field>
@ -102,9 +100,9 @@
<mat-label> GENDER: </mat-label> <mat-label> GENDER: </mat-label>
<mat-select id="gender" [(value)]="account.gender" formControlName="gender" <mat-select id="gender" [(value)]="account.gender" formControlName="gender"
[errorStateMatcher]="matcher"> [errorStateMatcher]="matcher">
<mat-option value="male"> MALE </mat-option> <mat-option *ngFor="let gender of genders" [value]="gender">
<mat-option value="female"> FEMALE </mat-option> {{gender | uppercase}}
<mat-option value="other"> OTHER </mat-option> </mat-option>
</mat-select> </mat-select>
<mat-error *ngIf="submitted && accountInfoFormStub.gender.errors">Gender is required.</mat-error> <mat-error *ngIf="submitted && accountInfoFormStub.gender.errors">Gender is required.</mat-error>
</mat-form-field> </mat-form-field>
@ -238,11 +236,9 @@
<mat-label> TRANSACTION TYPE </mat-label> <mat-label> TRANSACTION TYPE </mat-label>
<mat-select id="transferSelect" [(value)]="transactionsType" (selectionChange)="filterTransactions()"> <mat-select id="transferSelect" [(value)]="transactionsType" (selectionChange)="filterTransactions()">
<mat-option value="all">ALL TRANSFERS</mat-option> <mat-option value="all">ALL TRANSFERS</mat-option>
<mat-option value="transaction">PAYMENTS</mat-option> <mat-option *ngFor="let transactionType of transactionsTypes" [value]="transactionType">
<mat-option value="conversion">CONVERSION</mat-option> {{transactionType | uppercase}}
<mat-option value="disbursements">DISBURSEMENTS</mat-option> </mat-option>
<mat-option value="rewards">REWARDS</mat-option>
<mat-option value="reclamation">RECLAMATION</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<button mat-raised-button color="primary" type="button" class="btn btn-outline-primary ml-auto mr-2" (click)="downloadCsv(transactions, 'transactions')"> EXPORT </button> <button mat-raised-button color="primary" type="button" class="btn btn-outline-primary ml-auto mr-2" (click)="downloadCsv(transactions, 'transactions')"> EXPORT </button>
@ -312,11 +308,9 @@
<mat-label> ACCOUNT TYPE </mat-label> <mat-label> ACCOUNT TYPE </mat-label>
<mat-select id="typeSelect" [(value)]="accountsType" (selectionChange)="filterAccounts()"> <mat-select id="typeSelect" [(value)]="accountsType" (selectionChange)="filterAccounts()">
<mat-option value="all">ALL</mat-option> <mat-option value="all">ALL</mat-option>
<mat-option value="user">USER</mat-option> <mat-option *ngFor="let accountType of accountTypes" [value]="accountType">
<mat-option value="cashier">CASHIER</mat-option> {{accountType | uppercase}}
<mat-option value="vendor">VENDOR</mat-option> </mat-option>
<mat-option value="tokenAgent">TOKENAGENT</mat-option>
<mat-option value="group">GROUPACCOUNT</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<button mat-raised-button color="primary" type="button" class="btn btn-outline-primary ml-auto mr-2" (click)="downloadCsv(accounts, 'accounts')"> EXPORT </button> <button mat-raised-button color="primary" type="button" class="btn btn-outline-primary ml-auto mr-2" (click)="downloadCsv(accounts, 'accounts')"> EXPORT </button>

View File

@ -43,6 +43,9 @@ export class AccountDetailsComponent implements OnInit {
transaction: any; transaction: any;
transactions: any[]; transactions: any[];
transactionsType = 'all'; transactionsType = 'all';
accountTypes: any[];
transactionsTypes: any[];
genders: any[];
matcher = new CustomErrorStateMatcher(); matcher = new CustomErrorStateMatcher();
submitted: boolean = false; submitted: boolean = false;
bloxbergLink: string; bloxbergLink: string;
@ -102,6 +105,9 @@ export class AccountDetailsComponent implements OnInit {
this.userService.getCategories().pipe(first()).subscribe(res => this.categories = res); this.userService.getCategories().pipe(first()).subscribe(res => this.categories = res);
this.locationService.getAreaNames().pipe(first()).subscribe(res => this.areaNames = res); this.locationService.getAreaNames().pipe(first()).subscribe(res => this.areaNames = res);
this.locationService.getAreaTypes().pipe(first()).subscribe(res => this.areaTypes = res); this.locationService.getAreaTypes().pipe(first()).subscribe(res => this.areaTypes = res);
this.userService.getAccountTypes().pipe(first()).subscribe(res => this.accountTypes = res);
this.userService.getTransactionTypes().pipe(first()).subscribe(res => this.transactionsTypes = res);
this.userService.getGenders().pipe(first()).subscribe(res => this.genders = res);
} }
ngOnInit(): void { ngOnInit(): void {

View File

@ -26,11 +26,9 @@
<mat-label> ACCOUNT TYPE </mat-label> <mat-label> ACCOUNT TYPE </mat-label>
<mat-select id="typeSelect" [(value)]="accountsType" (selectionChange)="filterAccounts()"> <mat-select id="typeSelect" [(value)]="accountsType" (selectionChange)="filterAccounts()">
<mat-option value="all">ALL</mat-option> <mat-option value="all">ALL</mat-option>
<mat-option value="user">USER</mat-option> <mat-option *ngFor="let accountType of accountTypes" [value]="accountType">
<mat-option value="cashier">CASHIER</mat-option> {{accountType | uppercase}}
<mat-option value="vendor">VENDOR</mat-option> </mat-option>
<mat-option value="tokenAgent">TOKENAGENT</mat-option>
<mat-option value="group">GROUPACCOUNT</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<button mat-raised-button color="primary" type="button" class="btn btn-outline-primary ml-auto mr-2" routerLink="/accounts/search"> SEARCH </button> <button mat-raised-button color="primary" type="button" class="btn btn-outline-primary ml-auto mr-2" routerLink="/accounts/search"> SEARCH </button>

View File

@ -6,6 +6,7 @@ import {LoggingService, UserService} from '@app/_services';
import {Router} from '@angular/router'; import {Router} from '@angular/router';
import {exportCsv} from '@app/_helpers'; import {exportCsv} from '@app/_helpers';
import {strip0x} from '@src/assets/js/ethtx/dist/hex'; import {strip0x} from '@src/assets/js/ethtx/dist/hex';
import {first} from 'rxjs/operators';
@Component({ @Component({
selector: 'app-accounts', selector: 'app-accounts',
@ -20,6 +21,7 @@ export class AccountsComponent implements OnInit {
defaultPageSize = 10; defaultPageSize = 10;
pageSizeOptions = [10, 20, 50, 100]; pageSizeOptions = [10, 20, 50, 100];
accountsType = 'all'; accountsType = 'all';
accountTypes: any[];
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
@ -36,6 +38,7 @@ export class AccountsComponent implements OnInit {
this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, {error}); this.loggingService.sendErrorLevelMessage('Failed to load accounts', this, {error});
} }
})(); })();
this.userService.getAccountTypes().pipe(first()).subscribe(res => this.accountTypes = res);
} }
ngOnInit(): void { ngOnInit(): void {

View File

@ -27,11 +27,9 @@
<mat-form-field appearance="outline"> <mat-form-field appearance="outline">
<mat-label>Account Type: </mat-label> <mat-label>Account Type: </mat-label>
<mat-select id="accountType" formControlName="accountType" [errorStateMatcher]="matcher"> <mat-select id="accountType" formControlName="accountType" [errorStateMatcher]="matcher">
<mat-option value="user">USER</mat-option> <mat-option *ngFor="let accountType of accountTypes" [value]="accountType">
<mat-option value="cashier">CASHIER</mat-option> {{accountType | uppercase}}
<mat-option value="vendor">VENDOR</mat-option> </mat-option>
<mat-option value="tokenAgent">TOKENAGENT</mat-option>
<mat-option value="group">GROUPACCOUNT</mat-option>
</mat-select> </mat-select>
<mat-error *ngIf="submitted && createFormStub.accountType.errors">Account type is required.</mat-error> <mat-error *ngIf="submitted && createFormStub.accountType.errors">Account type is required.</mat-error>
</mat-form-field><br> </mat-form-field><br>
@ -93,9 +91,9 @@
<mat-form-field appearance="outline"> <mat-form-field appearance="outline">
<mat-label>Gender: </mat-label> <mat-label>Gender: </mat-label>
<mat-select id="gender" formControlName="gender" [errorStateMatcher]="matcher"> <mat-select id="gender" formControlName="gender" [errorStateMatcher]="matcher">
<mat-option value="female">FEMALE</mat-option> <mat-option *ngFor="let gender of genders" [value]="gender">
<mat-option value="male">MALE</mat-option> {{gender | uppercase}}
<mat-option value="other">OTHER</mat-option> </mat-option>
</mat-select> </mat-select>
<mat-error *ngIf="submitted && createFormStub.gender.errors">Gender is required.</mat-error> <mat-error *ngIf="submitted && createFormStub.gender.errors">Gender is required.</mat-error>
</mat-form-field><br> </mat-form-field><br>

View File

@ -16,6 +16,8 @@ export class CreateAccountComponent implements OnInit {
submitted: boolean = false; submitted: boolean = false;
categories: any[]; categories: any[];
areaNames: any[]; areaNames: any[];
accountTypes: any[];
genders: any[];
constructor( constructor(
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
@ -38,6 +40,8 @@ export class CreateAccountComponent implements OnInit {
}); });
this.userService.getCategories().pipe(first()).subscribe(res => this.categories = res); this.userService.getCategories().pipe(first()).subscribe(res => this.categories = res);
this.locationService.getAreaNames().pipe(first()).subscribe(res => this.areaNames = res); this.locationService.getAreaNames().pipe(first()).subscribe(res => this.areaNames = res);
this.userService.getAccountTypes().pipe(first()).subscribe(res => this.accountTypes = res);
this.userService.getGenders().pipe(first()).subscribe(res => this.genders = res);
} }
get createFormStub(): any { return this.createForm.controls; } get createFormStub(): any { return this.createForm.controls; }

View File

@ -29,11 +29,9 @@
<mat-label> TRANSFER TYPE </mat-label> <mat-label> TRANSFER TYPE </mat-label>
<mat-select id="typeSelect" [(value)]="transactionsType" (selectionChange)="filterTransactions()"> <mat-select id="typeSelect" [(value)]="transactionsType" (selectionChange)="filterTransactions()">
<mat-option value="all">ALL TRANSFERS</mat-option> <mat-option value="all">ALL TRANSFERS</mat-option>
<mat-option value="transaction">PAYMENTS</mat-option> <mat-option *ngFor="let transactionType of transactionsTypes" [value]="transactionType">
<mat-option value="conversion">CONVERSION</mat-option> {{transactionType | uppercase}}
<mat-option value="disbursements">DISBURSEMENTS</mat-option> </mat-option>
<mat-option value="rewards">REWARDS</mat-option>
<mat-option value="reclamation">RECLAMATION</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<button mat-raised-button color="primary" type="button" class="btn btn-outline-primary ml-auto mr-2" (click)="downloadCsv()"> EXPORT </button> <button mat-raised-button color="primary" type="button" class="btn btn-outline-primary ml-auto mr-2" (click)="downloadCsv()"> EXPORT </button>

View File

@ -1,9 +1,10 @@
import {AfterViewInit, ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core'; import {AfterViewInit, ChangeDetectionStrategy, Component, OnInit, ViewChild} from '@angular/core';
import {BlockSyncService, TransactionService} from '@app/_services'; import {BlockSyncService, TransactionService, UserService} from '@app/_services';
import {MatTableDataSource} from '@angular/material/table'; import {MatTableDataSource} from '@angular/material/table';
import {MatPaginator} from '@angular/material/paginator'; import {MatPaginator} from '@angular/material/paginator';
import {MatSort} from '@angular/material/sort'; import {MatSort} from '@angular/material/sort';
import {exportCsv} from '@app/_helpers'; import {exportCsv} from '@app/_helpers';
import {first} from 'rxjs/operators';
@Component({ @Component({
selector: 'app-transactions', selector: 'app-transactions',
@ -19,6 +20,7 @@ export class TransactionsComponent implements OnInit, AfterViewInit {
transactions: any[]; transactions: any[];
transaction: any; transaction: any;
transactionsType = 'all'; transactionsType = 'all';
transactionsTypes: any[];
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
@ -26,6 +28,7 @@ export class TransactionsComponent implements OnInit, AfterViewInit {
constructor( constructor(
private blockSyncService: BlockSyncService, private blockSyncService: BlockSyncService,
private transactionService: TransactionService, private transactionService: TransactionService,
private userService: UserService
) { ) {
this.blockSyncService.blockSync(); this.blockSyncService.blockSync();
} }
@ -37,6 +40,7 @@ export class TransactionsComponent implements OnInit, AfterViewInit {
this.transactionDataSource.sort = this.sort; this.transactionDataSource.sort = this.sort;
this.transactions = transactions; this.transactions = transactions;
}); });
this.userService.getTransactionTypes().pipe(first()).subscribe(res => this.transactionsTypes = res);
} }
viewTransaction(transaction): void { viewTransaction(transaction): void {