Cleanup services to use mock backend.
This commit is contained in:
parent
bff58f7a43
commit
156fa4067f
@ -2,3 +2,4 @@ export * from './transaction.service';
|
|||||||
export * from './user.service';
|
export * from './user.service';
|
||||||
export * from './token.service';
|
export * from './token.service';
|
||||||
export * from './block-sync.service';
|
export * from './block-sync.service';
|
||||||
|
export * from './location.service';
|
||||||
|
16
src/app/_services/location.service.spec.ts
Normal file
16
src/app/_services/location.service.spec.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { LocationService } from './location.service';
|
||||||
|
|
||||||
|
describe('LocationService', () => {
|
||||||
|
let service: LocationService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(LocationService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
22
src/app/_services/location.service.ts
Normal file
22
src/app/_services/location.service.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {BehaviorSubject} from 'rxjs';
|
||||||
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
import {environment} from '../../environments/environment';
|
||||||
|
import {first} from 'rxjs/operators';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class LocationService {
|
||||||
|
locations: any = '';
|
||||||
|
private locationsList = new BehaviorSubject<any>(this.locations);
|
||||||
|
locationsSubject = this.locationsList.asObservable();
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private http: HttpClient
|
||||||
|
) { }
|
||||||
|
|
||||||
|
getLocations(): void {
|
||||||
|
this.http.get(`${environment.cicCacheUrl}/locations`).pipe(first()).subscribe(locations => this.locationsList.next(locations));
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +1,26 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import {HttpClient} from '@angular/common/http';
|
||||||
|
import {environment} from '../../environments/environment';
|
||||||
|
import {first} from 'rxjs/operators';
|
||||||
|
import {BehaviorSubject} from 'rxjs';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class TokenService {
|
export class TokenService {
|
||||||
data = [
|
tokens: any = '';
|
||||||
{ name: 'Reserve', symbol: 'RSV' },
|
private tokensList = new BehaviorSubject<any>(this.tokens);
|
||||||
{ name: 'Bert', symbol: 'BRT' },
|
tokensSubject = this.tokensList.asObservable();
|
||||||
{ name: 'Ernie', symbol: 'ERN' },
|
|
||||||
{ name: 'Reserve', symbol: 'RSV' },
|
|
||||||
{ name: 'Bert', symbol: 'BRT' },
|
|
||||||
{ name: 'Ernie', symbol: 'ERN' },
|
|
||||||
{ name: 'Reserve', symbol: 'RSV' },
|
|
||||||
{ name: 'Bert', symbol: 'BRT' },
|
|
||||||
{ name: 'Ernie', symbol: 'ERN' },
|
|
||||||
{ name: 'Reserve', symbol: 'RSV' },
|
|
||||||
{ name: 'Bert', symbol: 'BRT' },
|
|
||||||
{ name: 'Ernie', symbol: 'ERN' },
|
|
||||||
];
|
|
||||||
|
|
||||||
constructor() { }
|
constructor(
|
||||||
|
private http: HttpClient
|
||||||
|
) { }
|
||||||
|
|
||||||
getBySymbol(symbol: string): any {
|
getTokens(): any {
|
||||||
return this.data.find(token => token.symbol === symbol);
|
this.http.get(`${environment.cicCacheUrl}/tokens`).pipe(first()).subscribe(tokens => this.tokensList.next(tokens));
|
||||||
|
}
|
||||||
|
|
||||||
|
getTokenBySymbol(symbol: string): any {
|
||||||
|
return this.http.get(`${environment.cicCacheUrl}/tokens/${symbol}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ import {HttpClient} from '@angular/common/http';
|
|||||||
import {first, map} from 'rxjs/operators';
|
import {first, map} from 'rxjs/operators';
|
||||||
import {BehaviorSubject, Observable} from 'rxjs';
|
import {BehaviorSubject, Observable} from 'rxjs';
|
||||||
import {environment} from '../../environments/environment';
|
import {environment} from '../../environments/environment';
|
||||||
import {Conversion, Transaction} from '../_models';
|
|
||||||
import {User} from 'cic-client-meta';
|
import {User} from 'cic-client-meta';
|
||||||
import {UserService} from './user.service';
|
import {UserService} from './user.service';
|
||||||
import {parse} from '../../assets/js/parse-vcard';
|
import {parse} from '../../assets/js/parse-vcard';
|
||||||
@ -12,12 +11,9 @@ import {parse} from '../../assets/js/parse-vcard';
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class TransactionService {
|
export class TransactionService {
|
||||||
transactions: Transaction[] = [];
|
transactions: any[] = [];
|
||||||
conversions: Conversion[] = [];
|
private transactionList = new BehaviorSubject<any[]>(this.transactions);
|
||||||
private transactionList = new BehaviorSubject<Transaction[]>(this.transactions);
|
|
||||||
transactionsSubject = this.transactionList.asObservable();
|
transactionsSubject = this.transactionList.asObservable();
|
||||||
private conversionList = new BehaviorSubject<Conversion[]>(this.conversions);
|
|
||||||
conversionsSubject = this.conversionList.asObservable();
|
|
||||||
userInfo: any;
|
userInfo: any;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -42,29 +38,35 @@ export class TransactionService {
|
|||||||
setTransaction(transaction, cacheSize: number): void {
|
setTransaction(transaction, cacheSize: number): void {
|
||||||
const cachedTransaction = this.transactions.find(cachedTx => cachedTx.tx.txHash === transaction.tx.txHash);
|
const cachedTransaction = this.transactions.find(cachedTx => cachedTx.tx.txHash === transaction.tx.txHash);
|
||||||
if (cachedTransaction) { return; }
|
if (cachedTransaction) { return; }
|
||||||
|
transaction.type = 'transaction';
|
||||||
this.getUser(transaction.from).then(() => {
|
this.getUser(transaction.from).then(() => {
|
||||||
transaction.sender = this.userInfo;
|
transaction.sender = this.userInfo;
|
||||||
this.getUser(transaction.to).then(() => {
|
this.getUser(transaction.to).then(() => {
|
||||||
transaction.recipient = this.userInfo;
|
transaction.recipient = this.userInfo;
|
||||||
this.transactions.unshift(transaction);
|
this.addTransaction(transaction, cacheSize);
|
||||||
if (this.transactions.length > cacheSize) {
|
|
||||||
this.transactions.length = cacheSize;
|
|
||||||
}
|
|
||||||
this.transactionList.next(this.transactions);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setConversion(conversion): void {
|
setConversion(conversion, cacheSize): void {
|
||||||
const cachedConversion = this.conversions.find(cachedTx => cachedTx.tx.txHash === conversion.tx.txHash);
|
const cachedConversion = this.transactions.find(cachedTx => cachedTx.tx.txHash === conversion.tx.txHash);
|
||||||
if (cachedConversion) { return; }
|
if (cachedConversion) { return; }
|
||||||
|
conversion.type = 'conversion';
|
||||||
this.getUser(conversion.trader).then(() => {
|
this.getUser(conversion.trader).then(() => {
|
||||||
conversion.user = this.userInfo;
|
conversion.sender = this.userInfo;
|
||||||
this.conversions.push(conversion);
|
conversion.recipient = this.userInfo;
|
||||||
this.conversionList.next(this.conversions);
|
this.addTransaction(conversion, cacheSize);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addTransaction(transaction, cacheSize: number): void {
|
||||||
|
this.transactions.unshift(transaction);
|
||||||
|
if (this.transactions.length > cacheSize) {
|
||||||
|
this.transactions.length = cacheSize;
|
||||||
|
}
|
||||||
|
this.transactionList.next(this.transactions);
|
||||||
|
}
|
||||||
|
|
||||||
async getUser(address: string): Promise<void> {
|
async getUser(address: string): Promise<void> {
|
||||||
this.userService.getUser(await User.toKey(address)).pipe(first()).subscribe(res => {
|
this.userService.getUser(await User.toKey(address)).pipe(first()).subscribe(res => {
|
||||||
const vcard = parse(atob(res.vcard));
|
const vcard = parse(atob(res.vcard));
|
||||||
|
@ -1,46 +1,75 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {Observable} from 'rxjs';
|
import {BehaviorSubject, Observable} from 'rxjs';
|
||||||
import {HttpClient, HttpParams} from '@angular/common/http';
|
import {HttpClient, HttpParams} from '@angular/common/http';
|
||||||
import {environment} from '../../environments/environment';
|
import {environment} from '../../environments/environment';
|
||||||
import {map} from 'rxjs/operators';
|
import {first, map} from 'rxjs/operators';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class UserService {
|
export class UserService {
|
||||||
users = [
|
accounts: any = '';
|
||||||
{id: 1, name: 'John Doe', phone: '+25412345678', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '08/16/2020', balance: '12987', failedPinAttempts: 1, status: 'approved', bio: 'Bodaboda', gender: 'male'},
|
private accountsList = new BehaviorSubject<any>(this.accounts);
|
||||||
{id: 2, name: 'Jane Buck', phone: '+25412341234', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'vendor', created: '04/02/2020', balance: '56281', failedPinAttempts: 0, status: 'approved', bio: 'Groceries', gender: 'female'},
|
accountsSubject = this.accountsList.asObservable();
|
||||||
{id: 3, name: 'Mc Donald', phone: '+25498765432', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'group', created: '11/16/2020', balance: '450', failedPinAttempts: 2, status: 'unapproved', bio: 'Food', gender: 'male'},
|
|
||||||
{id: 4, name: 'Hera Cles', phone: '+25498769876', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '05/28/2020', balance: '5621', failedPinAttempts: 3, status: 'approved', bio: 'Shop', gender: 'female'},
|
actions: any = '';
|
||||||
{id: 5, name: 'Silver Fia', phone: '+25462518374', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'token agent', created: '10/10/2020', balance: '817', failedPinAttempts: 0, status: 'unapproved', bio: 'Electronics', gender: 'male'},
|
private actionsList = new BehaviorSubject<any>(this.actions);
|
||||||
{id: 1, name: 'John Doe', phone: '+25412345678', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '08/16/2020', balance: '12987', failedPinAttempts: 1, status: 'approved', bio: 'Bodaboda', gender: 'male'},
|
actionsSubject = this.actionsList.asObservable();
|
||||||
{id: 2, name: 'Jane Buck', phone: '+25412341234', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'vendor', created: '04/02/2020', balance: '56281', failedPinAttempts: 0, status: 'approved', bio: 'Groceries', gender: 'female'},
|
|
||||||
{id: 3, name: 'Mc Donald', phone: '+25498765432', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'group', created: '11/16/2020', balance: '450', failedPinAttempts: 2, status: 'unapproved', bio: 'Food', gender: 'male'},
|
staff: any = '';
|
||||||
{id: 4, name: 'Hera Cles', phone: '+25498769876', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '05/28/2020', balance: '5621', failedPinAttempts: 3, status: 'approved', bio: 'Shop', gender: 'female'},
|
private staffList = new BehaviorSubject<any>(this.staff);
|
||||||
{id: 5, name: 'Silver Fia', phone: '+25462518374', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'token agent', created: '10/10/2020', balance: '817', failedPinAttempts: 0, status: 'unapproved', bio: 'Electronics', gender: 'male'},
|
staffSubject = this.staffList.asObservable();
|
||||||
{id: 1, name: 'John Doe', phone: '+25412345678', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '08/16/2020', balance: '12987', failedPinAttempts: 1, status: 'approved', bio: 'Bodaboda', gender: 'male'},
|
|
||||||
{id: 2, name: 'Jane Buck', phone: '+25412341234', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'vendor', created: '04/02/2020', balance: '56281', failedPinAttempts: 0, status: 'approved', bio: 'Groceries', gender: 'female'},
|
|
||||||
{id: 3, name: 'Mc Donald', phone: '+25498765432', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'group', created: '11/16/2020', balance: '450', failedPinAttempts: 2, status: 'unapproved', bio: 'Food', gender: 'male'},
|
|
||||||
{id: 4, name: 'Hera Cles', phone: '+25498769876', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '05/28/2020', balance: '5621', failedPinAttempts: 3, status: 'approved', bio: 'Shop', gender: 'female'},
|
|
||||||
{id: 5, name: 'Silver Fia', phone: '+25462518374', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'token agent', created: '10/10/2020', balance: '817', failedPinAttempts: 0, status: 'unapproved', bio: 'Electronics', gender: 'male'},
|
|
||||||
{id: 1, name: 'John Doe', phone: '+25412345678', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '08/16/2020', balance: '12987', failedPinAttempts: 1, status: 'approved', bio: 'Bodaboda', gender: 'male'},
|
|
||||||
{id: 2, name: 'Jane Buck', phone: '+25412341234', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'vendor', created: '04/02/2020', balance: '56281', failedPinAttempts: 0, status: 'approved', bio: 'Groceries', gender: 'female'},
|
|
||||||
{id: 3, name: 'Mc Donald', phone: '+25498765432', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'group', created: '11/16/2020', balance: '450', failedPinAttempts: 2, status: 'unapproved', bio: 'Food', gender: 'male'},
|
|
||||||
{id: 4, name: 'Hera Cles', phone: '+25498769876', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '05/28/2020', balance: '5621', failedPinAttempts: 3, status: 'approved', bio: 'Shop', gender: 'female'},
|
|
||||||
{id: 5, name: 'Silver Fia', phone: '+25462518374', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'token agent', created: '10/10/2020', balance: '817', failedPinAttempts: 0, status: 'unapproved', bio: 'Electronics', gender: 'male'},
|
|
||||||
];
|
|
||||||
actions = [
|
|
||||||
{ id: 1, user: 'Tom', role: 'enroller', action: 'Disburse RSV 100', approval: false },
|
|
||||||
{ id: 2, user: 'Christine', role: 'admin', action: 'Change user phone number', approval: true },
|
|
||||||
{ id: 3, user: 'Will', role: 'superadmin', action: 'Reclaim RSV 1000', approval: true },
|
|
||||||
{ id: 4, user: 'Vivian', role: 'enroller', action: 'Complete user profile', approval: true },
|
|
||||||
{ id: 5, user: 'Jack', role: 'enroller', action: 'Reclaim RSV 200', approval: false },
|
|
||||||
{ id: 6, user: 'Patience', role: 'enroller', action: 'Change user information', approval: false }
|
|
||||||
];
|
|
||||||
|
|
||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
|
getAccounts(): void {
|
||||||
|
this.http.get(`${environment.cicCacheUrl}/accounts`).pipe(first()).subscribe(accounts => this.accountsList.next(accounts));
|
||||||
|
}
|
||||||
|
|
||||||
|
getAccountById(id: number): Observable<any> {
|
||||||
|
return this.http.get(`${environment.cicCacheUrl}/accounts/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
getActions(): void {
|
||||||
|
this.http.get(`${environment.cicCacheUrl}/actions`).pipe(first()).subscribe(actions => this.actionsList.next(actions));
|
||||||
|
}
|
||||||
|
|
||||||
|
getActionById(id: string): any {
|
||||||
|
return this.http.get(`${environment.cicCacheUrl}/actions/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
approveAction(id: string): Observable<any> {
|
||||||
|
return this.http.post(`${environment.cicCacheUrl}/actions/${id}`, { approval: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
revokeAction(id: string): Observable<any> {
|
||||||
|
return this.http.post(`${environment.cicCacheUrl}/actions/${id}`, { approval: false });
|
||||||
|
}
|
||||||
|
|
||||||
|
getHistoryByUser(id: string): Observable<any> {
|
||||||
|
return this.http.get(`${environment.cicCacheUrl}/history/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
getStaff(): void {
|
||||||
|
this.http.get(`${environment.cicCacheUrl}/staff`).pipe(first()).subscribe(staff => this.staffList.next(staff));
|
||||||
|
}
|
||||||
|
|
||||||
|
getStaffById(id: string): Observable<any> {
|
||||||
|
return this.http.get(`${environment.cicCacheUrl}/staff/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
activateStaff(id: string): Observable<any> {
|
||||||
|
return this.http.post(`${environment.cicCacheUrl}/staff/${id}`, {status: 'activated'});
|
||||||
|
}
|
||||||
|
|
||||||
|
deactivateStaff(id: string): Observable<any> {
|
||||||
|
return this.http.post(`${environment.cicCacheUrl}/staff/${id}`, {status: 'deactivated'});
|
||||||
|
}
|
||||||
|
|
||||||
|
changeStaffType(id: string, type: string): Observable<any> {
|
||||||
|
return this.http.post(`${environment.cicCacheUrl}/staff/${id}`, {accountType: type});
|
||||||
|
}
|
||||||
|
|
||||||
getUser(userKey: string): Observable<any> {
|
getUser(userKey: string): Observable<any> {
|
||||||
const params = new HttpParams().set('userKey', '0970c6e9cdad650ba9006e5a1caf090a13da312792389a147263c98ac78cd037');
|
const params = new HttpParams().set('userKey', '0970c6e9cdad650ba9006e5a1caf090a13da312792389a147263c98ac78cd037');
|
||||||
return this.http.get(`${environment.cicScriptsUrl}`, { params })
|
return this.http.get(`${environment.cicScriptsUrl}`, { params })
|
||||||
@ -48,22 +77,4 @@ export class UserService {
|
|||||||
return response;
|
return response;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserById(id: string): any {
|
|
||||||
return this.users.find(user => user.id === parseInt(id, 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
getActionById(id: string): any {
|
|
||||||
return this.actions.find(action => action.id === parseInt(id, 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
approveAction(id: string): void {
|
|
||||||
const action = this.actions.find(queriedAction => queriedAction.id === parseInt(id, 10));
|
|
||||||
action.approval = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
revokeAction(id: string): void {
|
|
||||||
const action = this.actions.find(queriedAction => queriedAction.id === parseInt(id, 10));
|
|
||||||
action.approval = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user