1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { catchError, map } from 'rxjs/operators';
- import { CompanyActionTypes } from './company.action.type';
- import {
- CompanyActionUnion,
- CreateFormUpdateCompanyActionSuccess,
- CreateFormUpdateCompanyActionError,
- UpdateCompanyActionSuccss,
- UpdateCompanyActionError,
- } from './company.actions';
- import { Observable, mergeMap, of } from 'rxjs';
- import { Actions, createEffect, ofType } from '@ngrx/effects';
- import { CompanyService } from './../../shared/services/company.service';
- import { Injectable } from '@angular/core';
- import { Company } from 'src/app/shared/models/company/company.model';
-
- @Injectable()
- export class CompanyUpdateEffects {
- constructor(
- private companyService: CompanyService,
- private companyActions: Actions
- ) {}
-
- //create form update company effect
- createFormUpdateCompanyEffect: Observable<CompanyActionUnion> = createEffect(
- () =>
- this.companyActions.pipe(
- ofType(CompanyActionTypes.CREATE_FORM_UPDATE_COMPANY),
- mergeMap((action: CompanyActionUnion) => {
- return this.companyService
- .getCompanyByIDService(action.payload.companyID)
- .pipe(
- map(
- (company: Company) =>
- new CreateFormUpdateCompanyActionSuccess(company)
- ),
- catchError((err) =>
- of(new CreateFormUpdateCompanyActionError(err))
- )
- );
- })
- )
- );
-
- //update company
- updateCompanyEffect : Observable<CompanyActionUnion> = createEffect(
- ()=> this.companyActions.pipe(
- ofType(CompanyActionTypes.UPDATE_COMPANY),
- mergeMap( (action: CompanyActionUnion) =>{
- return this.companyService.updateCompanyService(action.payload).pipe(
- map( (company: Company) => new UpdateCompanyActionSuccss(company)),
- catchError( err => of (new UpdateCompanyActionError(err)) )
- )
- })
- )
- )
- }
|