src/app/guards/duplicate-payment.guard.ts
Properties |
Methods |
constructor(paymentService: PaymentService, app: AppState, router: Router)
|
||||||||||||
Defined in src/app/guards/duplicate-payment.guard.ts:13
|
||||||||||||
Parameters :
|
canActivate |
canActivate()
|
Defined in src/app/guards/duplicate-payment.guard.ts:20
|
Returns :
any
|
earliestStandardElectronicScheduleForDate |
earliestStandardElectronicScheduleForDate:
|
Type : Observable<string>
|
Defined in src/app/guards/duplicate-payment.guard.ts:13
|
errorStore |
errorStore:
|
Type : any
|
Defined in src/app/guards/duplicate-payment.guard.ts:11
|
setDeliveryDate$ |
setDeliveryDate$:
|
Type : Observable<any>
|
Defined in src/app/guards/duplicate-payment.guard.ts:12
|
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators/map';
import { PaymentService } from '../services/payment.service';
import { AppState } from '../stores/app-state.store';
@Injectable()
export class DuplicatePaymentGuard implements CanActivate {
errorStore: any;
setDeliveryDate$: Observable<any>;
earliestStandardElectronicScheduleForDate: Observable<string>;
constructor(
private paymentService: PaymentService,
private app: AppState,
private router: Router
) {}
canActivate() {
console.log('Dupe guard start');
return this.paymentService.findDuplicate().pipe(
map((duplicate) => {
if (this.app.acknowledgeDuplicate) {
console.log('Dupe guard passed with acknowledgement');
return true;
}
if (duplicate) {
console.log('Dupe guard failed: a duplicated payment was found');
this.router.navigate(['/duplicate-payment-alert']);
return false;
}
console.log('Dupe guard passed: no duplicated payments were found');
return true;
})
);
}
}