All files / src/app/core/store/customer/data-requests data-requests.reducer.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 1/1
100% Lines 6/6

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 3823x     23x   23x                       23x           23x               2x            
import { createReducer, on } from '@ngrx/store';
 
import { HttpError } from 'ish-core/models/http-error/http-error.model';
import { setErrorOn, setLoadingOn, unsetLoadingOn } from 'ish-core/utils/ngrx-creators';
 
import {
  confirmGDPRDataRequest,
  confirmGDPRDataRequestFail,
  confirmGDPRDataRequestSuccess,
} from './data-requests.actions';
 
export interface DataRequestsState {
  loading: boolean;
  error: HttpError;
  firstGDPRDataRequest: boolean;
}
 
const initialState: DataRequestsState = {
  loading: false,
  error: undefined,
  firstGDPRDataRequest: true,
};
 
export const dataRequestsReducer = createReducer(
  initialState,
  setLoadingOn(confirmGDPRDataRequest),
  unsetLoadingOn(confirmGDPRDataRequestSuccess, confirmGDPRDataRequestFail),
  setErrorOn(confirmGDPRDataRequestFail),
 
  on(
    confirmGDPRDataRequestSuccess,
    (state, action): DataRequestsState => ({
      ...state,
      firstGDPRDataRequest: action.payload.infoCode === 'gdpr_request.confirmed.info',
    })
  )
);