summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts
blob: c192ece481bbb2ae48708486cdae278954f0b837 (plain)
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
import * as _ from "lodash";
import {ActionOnFirstLevel} from "./firstLevel/firstLevel.actions";
import {ServiceInstanceActions} from "../../models/serviceInstanceActions";
import {ServiceState} from "./main.reducer";

export function deleteFirstLevel(state: ServiceState, action: ActionOnFirstLevel,shouldUpdateServiceValidationCounter: boolean){
  let newState = _.cloneDeep(state);
  let firstLevel = newState.serviceInstance[action.serviceId][action.firstLevelName][action.storeKey];
  let oldAction = firstLevel.action;
  if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState;
  if (shouldUpdateServiceValidationCounter){
    updateServiceValidationCounter(newState, firstLevel['isMissingData'], false, action.serviceId);
  }
  newState.serviceInstance[action.serviceId][action.firstLevelName][action.storeKey].action = (oldAction + '_Delete') as ServiceInstanceActions;
  return newState;
}

export function updateServiceValidationCounter(newState: any, oldValidationState: boolean, newValidationState: boolean, serviceUuid: string) {
  if (oldValidationState && !newValidationState) {
    newState.serviceInstance[serviceUuid].validationCounter--;
  } else if (!oldValidationState && newValidationState) {
    newState.serviceInstance[serviceUuid].validationCounter++;
  }
  resetUpgradeStatus(newState, serviceUuid);
};

function resetUpgradeStatus(newState: any, serviceUuid: string){
  newState.serviceInstance[serviceUuid].upgradedVFMSonsCounter = 0;
  newState.serviceInstance[serviceUuid].isUpgraded = false;
}