import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/switchMap'; import 'rxjs/add/operator/debounceTime'; import { Injectable } from '@angular/core'; import { Effect, Actions } from '@ngrx/effects'; import { Action } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; import { of } from 'rxjs/observable/of'; import * as errorActions from '../actions/errors'; import { DataFetcher } from '../services/data-fetcher/data-fetcher.service'; import * as modaleActions from '../actions/modal.actions'; import { apiUrls } from '@hdca/fe-angular-shared'; import { ApiParamInfoService } from '@hdca/fe-angular-shared'; import { CartStoreLocator } from '../models/cart-store-locator.interface'; const errorUrl: string = null; @Injectable() export class ModalEffects { apiParams: any; @Effect() getPickUpStores$: Observable = this.actions$ .ofType(modaleActions.LOAD_PICK_UP_STORES) .switchMap(action => { this.apiParams = this.apiParamService.getApiParamInfo(); return ( this.serviceData .fetch( apiUrls.BASE_URL + apiUrls.PICK_UP_STORES( this.apiParams.customerId, this.apiParams.cartId, action['section'], action['entryNumber'], action['query'], this.apiParams.full, this.apiParams.catalogVersion, this.apiParams.lang ), this.apiParams.lang, { req: 'get' } ) .map((result: CartStoreLocator) => { return new modaleActions.LoadPickUpStoresSuccessAction( result.stores ); }) .catch(err => of( new errorActions.ToggleApiError( err, errorUrl, apiUrls.BASE_URL + apiUrls.PICK_UP_STORES( this.apiParams.customerId, this.apiParams.cartId, action['section'], action['entryNumber'], action['query'], this.apiParams.full, this.apiParams.catalogVersion, this.apiParams.lang ) ) ) ) ); }); constructor( private actions$: Actions, private serviceData: DataFetcher, private apiParamService: ApiParamInfoService ) {} }