All files / src/app/extensions/punchout/store/punchout-users punchout-users.reducer.ts

72.72% Statements 8/11
100% Branches 0/0
25% Functions 1/4
72.72% Lines 8/11

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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 6414x 14x     14x       14x                             14x             14x         14x                         5x                              
import { EntityState, createEntityAdapter } from '@ngrx/entity';
import { createReducer, on } from '@ngrx/store';
 
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { setErrorOn, setLoadingOn, unsetLoadingAndErrorOn } from 'ish-core/utils/ngrx-creators';
 
import { PunchoutUser } from '../../models/punchout-user/punchout-user.model';
 
import {
  addPunchoutUser,
  addPunchoutUserFail,
  addPunchoutUserSuccess,
  deletePunchoutUser,
  deletePunchoutUserFail,
  deletePunchoutUserSuccess,
  loadPunchoutUsers,
  loadPunchoutUsersFail,
  loadPunchoutUsersSuccess,
  updatePunchoutUser,
  updatePunchoutUserFail,
  updatePunchoutUserSuccess,
} from './punchout-users.actions';
 
export const punchoutUsersAdapter = createEntityAdapter<PunchoutUser>();
 
export interface PunchoutUsersState extends EntityState<PunchoutUser> {
  loading: boolean;
  error: HttpError;
}
 
export const initialState: PunchoutUsersState = punchoutUsersAdapter.getInitialState({
  loading: false,
  error: undefined,
});
 
export const punchoutUsersReducer = createReducer(
  initialState,
  setLoadingOn(loadPunchoutUsers, addPunchoutUser, updatePunchoutUser, deletePunchoutUser),
  setErrorOn(loadPunchoutUsersFail, addPunchoutUserFail, updatePunchoutUserFail, deletePunchoutUserFail),
  unsetLoadingAndErrorOn(
    loadPunchoutUsersSuccess,
    addPunchoutUserSuccess,
    updatePunchoutUserSuccess,
    deletePunchoutUserSuccess
  ),
 
  on(
    loadPunchoutUsersSuccess,
    (state, action): PunchoutUsersState => punchoutUsersAdapter.upsertMany(action.payload.users, state)
  ),
  on(
    addPunchoutUserSuccess,
    (state, action): PunchoutUsersState => punchoutUsersAdapter.addOne(action.payload.user, state)
  ),
  on(
    updatePunchoutUserSuccess,
    (state, action): PunchoutUsersState => punchoutUsersAdapter.upsertOne(action.payload.user, state)
  ),
  on(
    deletePunchoutUserSuccess,
    (state, action): PunchoutUsersState => punchoutUsersAdapter.removeOne(action.payload.login, state)
  )
);