import { Injectable } from '@angular/core'; import { Actions, Effect, ofType } from '@ngrx/effects'; import { DarsActionTypes } from '@app/dars/store/actions'; import * as darsActions from '@app/dars/store/actions'; import { flatMap, map, catchError } from 'rxjs/operators'; import { DarsApiService } from '../services/api.service'; import { of } from 'rxjs'; @Injectable() export class DARSEffects { constructor(private actions$: Actions, private api: DarsApiService) {} @Effect() load$ = this.actions$.pipe( ofType(DarsActionTypes.StartLoadingMetadata), flatMap(() => this.api.getAudits()), map(metadata => new darsActions.AddAuditMetadata({ metadata })), catchError(() => { return of( new darsActions.ErrorLoadingMetadata({ message: 'Unable to load audit metadata. Please try again', }), ); }), ); }