Application de gestion de projets. Un projet doit affecté à un utilisateur et une société qui existent

company.effects.update.ts 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { catchError, map } from 'rxjs/operators';
  2. import { CompanyActionTypes } from './company.action.type';
  3. import {
  4. CompanyActionUnion,
  5. CreateFormUpdateCompanyActionSuccess,
  6. CreateFormUpdateCompanyActionError,
  7. UpdateCompanyActionSuccss,
  8. UpdateCompanyActionError,
  9. } from './company.actions';
  10. import { Observable, mergeMap, of } from 'rxjs';
  11. import { Actions, createEffect, ofType } from '@ngrx/effects';
  12. import { CompanyService } from './../../shared/services/company.service';
  13. import { Injectable } from '@angular/core';
  14. import { Company } from 'src/app/shared/models/company/company.model';
  15. @Injectable()
  16. export class CompanyUpdateEffects {
  17. constructor(
  18. private companyService: CompanyService,
  19. private companyActions: Actions
  20. ) {}
  21. //create form update company effect
  22. createFormUpdateCompanyEffect: Observable<CompanyActionUnion> = createEffect(
  23. () =>
  24. this.companyActions.pipe(
  25. ofType(CompanyActionTypes.CREATE_FORM_UPDATE_COMPANY),
  26. mergeMap((action: CompanyActionUnion) => {
  27. return this.companyService
  28. .getCompanyByIDService(action.payload.companyID)
  29. .pipe(
  30. map(
  31. (company: Company) =>
  32. new CreateFormUpdateCompanyActionSuccess(company)
  33. ),
  34. catchError((err) =>
  35. of(new CreateFormUpdateCompanyActionError(err))
  36. )
  37. );
  38. })
  39. )
  40. );
  41. //update company
  42. updateCompanyEffect : Observable<CompanyActionUnion> = createEffect(
  43. ()=> this.companyActions.pipe(
  44. ofType(CompanyActionTypes.UPDATE_COMPANY),
  45. mergeMap( (action: CompanyActionUnion) =>{
  46. return this.companyService.updateCompanyService(action.payload).pipe(
  47. map( (company: Company) => new UpdateCompanyActionSuccss(company)),
  48. catchError( err => of (new UpdateCompanyActionError(err)) )
  49. )
  50. })
  51. )
  52. )
  53. }

Powered by TurnKey Linux.