File

src/app/guards/duplicate-payment.guard.ts

Index

Properties
Methods

Constructor

constructor(paymentService: PaymentService, app: AppState, router: Router)
Parameters :
Name Type Optional
paymentService PaymentService no
app AppState no
router Router no

Methods

canActivate
canActivate()
Returns : any

Properties

earliestStandardElectronicScheduleForDate
earliestStandardElectronicScheduleForDate: Observable<string>
Type : Observable<string>
errorStore
errorStore: any
Type : any
setDeliveryDate$
setDeliveryDate$: Observable<any>
Type : Observable<any>
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;
      })
    );
  }
}

results matching ""

    No results matching ""