All files / projects/organization-management/src/app/store/budget budget.effects.ts

100% Statements 13/13
75% Branches 6/8
100% Functions 4/4
100% Lines 12/12

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 276x 6x 6x   6x   6x   6x     6x 4x   4x 4x     6x 5x              
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { map, switchMap } from 'rxjs/operators';
 
import { mapErrorToAction } from 'ish-core/utils/operators';
 
import { UsersService } from '../../services/users/users.service';
 
import { loadBudget, loadBudgetFail, loadBudgetSuccess } from './budget.actions';
 
@Injectable()
export class BudgetEffects {
  constructor(private actions$: Actions, private usersService: UsersService) {}
 
  loadBudget$ = createEffect(() =>
    this.actions$.pipe(
      ofType(loadBudget),
      switchMap(() =>
        this.usersService.getCurrentUserBudget().pipe(
          map(budget => loadBudgetSuccess({ budget })),
          mapErrorToAction(loadBudgetFail)
        )
      )
    )
  );
}