All files / src/app/extensions/punchout/store/oci-configuration oci-configuration.effects.ts

100% Statements 25/25
75% Branches 6/8
100% Functions 12/12
100% Lines 24/24

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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 686x 6x 6x   6x 6x   6x   6x     6x 10x   10x 10x   3x             10x 10x     7x 4x             10x 10x     7x 4x             10x 10x       7x 4x                        
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { concatMap, map, mergeMap, switchMap } from 'rxjs/operators';
 
import { displaySuccessMessage } from 'ish-core/store/core/messages';
import { mapErrorToAction, mapToPayloadProperty } from 'ish-core/utils/operators';
 
import { PunchoutService } from '../../services/punchout/punchout.service';
 
import { ociConfigurationActions, ociConfigurationApiActions } from './oci-configuration.actions';
 
@Injectable()
export class OciConfigurationEffects {
  constructor(private actions$: Actions, private punchoutService: PunchoutService) {}
 
  loadOciOptionsAndConfiguration$ = createEffect(() =>
    this.actions$.pipe(
      ofType(ociConfigurationActions.loadOCIOptionsAndConfiguration),
      concatMap(() => [
        ociConfigurationActions.loadOCIConfigurationOptions(),
        ociConfigurationActions.loadOCIConfiguration(),
      ])
    )
  );
 
  loadOciConfigurationOptions$ = createEffect(() =>
    this.actions$.pipe(
      ofType(ociConfigurationActions.loadOCIConfigurationOptions),
      switchMap(() =>
        this.punchoutService.getOciConfigurationOptions().pipe(
          map(options => ociConfigurationApiActions.loadOCIConfigurationOptionsSuccess({ options })),
          mapErrorToAction(ociConfigurationApiActions.loadOCIConfigurationOptionsFail)
        )
      )
    )
  );
 
  loadOciConfiguration$ = createEffect(() =>
    this.actions$.pipe(
      ofType(ociConfigurationActions.loadOCIConfiguration),
      switchMap(() =>
        this.punchoutService.getOciConfiguration().pipe(
          map(configuration => ociConfigurationApiActions.loadOCIConfigurationSuccess({ configuration })),
          mapErrorToAction(ociConfigurationApiActions.loadOCIConfigurationFail)
        )
      )
    )
  );
 
  updateOciConfiguration$ = createEffect(() =>
    this.actions$.pipe(
      ofType(ociConfigurationActions.updateOCIConfiguration),
      mapToPayloadProperty('configuration'),
      concatMap(configuration =>
        this.punchoutService.updateOciConfiguration(configuration).pipe(
          mergeMap(configuration => [
            ociConfigurationApiActions.updateOCIConfigurationSuccess({ configuration }),
            displaySuccessMessage({
              message: 'account.punchout.configuration.save_success.message',
            }),
          ]),
          mapErrorToAction(ociConfigurationApiActions.updateOCIConfigurationFail)
        )
      )
    )
  );
}