src/app/services/limits.service.ts
Methods |
constructor(sessionStore: SessionStore, http: HttpClient)
|
|||||||||
Defined in src/app/services/limits.service.ts:12
|
|||||||||
Parameters :
|
verify | ||||||
verify(amount?: Number)
|
||||||
Defined in src/app/services/limits.service.ts:15
|
||||||
Parameters :
Returns :
Observable<LimitsResult>
|
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { combineLatest } from 'rxjs/observable/combineLatest';
import { of } from 'rxjs/observable/of';
import { catchError, filter, map } from 'rxjs/operators';
import { ACCOUNT_TYPES, LIMITS_API } from '../app.constants';
import { LimitsResult } from '../models/limits-result.model';
import { SessionStore } from '../stores/session.store';
@Injectable()
export class LimitsService {
constructor(private sessionStore: SessionStore, private http: HttpClient) {}
verify(amount?: Number): Observable<LimitsResult> {
if (!amount) {
return of(new LimitsResult());
}
const callable$ = this.http.get(`${LIMITS_API}/verify?amount=${amount}&type=${ACCOUNT_TYPES.ELECTRONIC}`);
const session$ = this.sessionStore.session$;
return combineLatest(session$, callable$).pipe(
filter(([session, response]) => session !== null && session !== undefined),
map(([session, response]) => {
const result = new LimitsResult();
const limits = session.limits;
if (limits.electronic.verify < amount) {
result.requiresMfa = true;
}
return result;
}),
catchError((response) => {
// The backedn returned an unsuccessful response code.
console.error(
`Backend returned code ${response.status}, ` + `body was: ${response.error}`
);
const result = new LimitsResult();
result.addError(response.error);
return of(result);
})
);
}
}