All files / src/app/core/store/customer/data-requests data-requests.effects.ts

100% Statements 18/18
75% Branches 6/8
100% Functions 6/6
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 4624x 24x 24x 24x   24x 24x 24x   24x             24x 7x   7x 7x       7x                   7x 7x     1x   1x          
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { routerNavigatedAction } from '@ngrx/router-store';
import { concatMap, filter, map } from 'rxjs/operators';
 
import { DataRequestsService } from 'ish-core/services/data-requests/data-requests.service';
import { mapToRouterState } from 'ish-core/store/core/router';
import { mapErrorToAction, mapToPayload } from 'ish-core/utils/operators';
 
import {
  confirmGDPRDataRequest,
  confirmGDPRDataRequestFail,
  confirmGDPRDataRequestSuccess,
} from './data-requests.actions';
 
@Injectable()
export class DataRequestsEffects {
  constructor(private actions$: Actions, private dataRequestsService: DataRequestsService) {}
 
  confirmGDPRDataRequest$ = createEffect(() =>
    this.actions$.pipe(
      ofType(confirmGDPRDataRequest),
      mapToPayload(),
      concatMap(payload =>
        this.dataRequestsService
          .confirmGDPRDataRequest(payload.data)
          .pipe(map(confirmGDPRDataRequestSuccess), mapErrorToAction(confirmGDPRDataRequestFail))
      )
    )
  );
 
  /**
   * Listener for GDPR email routing. If route is called the action {@link confirmGDPRDataRequest} is dispatched.
   */
  routeListenerForDataRequests$ = createEffect(() =>
    this.actions$.pipe(
      ofType(routerNavigatedAction),
      mapToRouterState(),
      filter(routerState => /^\/(gdpr-requests*)/.test(routerState.url)),
      map(({ queryParams }) =>
        confirmGDPRDataRequest({ data: { hash: queryParams.Hash, requestID: queryParams.PersonalDataRequestID } })
      )
    )
  );
}