export function reducer()

in src/app/groups/store/groups.reducer.ts [32:70]


export function reducer(state = initialState, action: group.Actions | groupTasks.Actions): ResourceState {

  switch (action.type) {

    case groupTasks.EXECUTE_COMMAND_SUCCESS: {
      const payload = action.payload;

      const groupId = payload.groupId;
      const command: GroupCommand = payload.command;

      const group = state.entities[groupId];

      let groupState: GroupState = null;

      if (command.action === 'ACTIVATE') {
        groupState = 'ACTIVE';
      }else if (command.action === 'CLOSE') {
        groupState = 'CLOSED';
      }else if (command.action === 'REOPEN') {
        groupState = 'ACTIVE';
      }

      group.currentState = groupState;

      return {
        ids: [ ...state.ids ],
        entities: Object.assign({}, state.entities, {
          [group.identifier]: group
        }),
        loadedAt: state.loadedAt,
        selectedId: state.selectedId
      };
    }

    default: {
      return state;
    }
  }
}