export function reducer()

in src/app/accounting/store/account/accounts.reducer.ts [33:71]


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

  switch (action.type) {

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

      const accountId = payload.accountId;
      const command: AccountCommand = payload.command;

      const account: Account = state.entities[accountId];

      let accountState: AccountState = null;

      if (command.action === 'LOCK') {
        accountState = 'LOCKED';
      } else if (command.action === 'UNLOCK' || command.action === 'REOPEN') {
        accountState = 'OPEN';
      } else if (command.action === 'CLOSE') {
        accountState = 'CLOSED';
      }

      account.state = accountState;

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

    default: {
      return state;
    }
  }
}