export function reducer()

in src/app/accounting/store/ledger/journal-entry/search.reducer.ts [39:77]


export function reducer(state = initialState, action: journalEntry.Actions): State {

  switch (action.type) {

    case journalEntry.SEARCH: {
      const payload = action.payload;

      return Object.assign({}, state, {
        startDate: payload.startDate,
        endDate: payload.endDate,
        loading: true
      });
    }

    case journalEntry.SEARCH_COMPLETE: {
      const journalEntries = action.payload;

      const journalEntryIds = journalEntries.map(journalEntry => journalEntry.transactionIdentifier);

      const newJournalEntryEntities = journalEntries.reduce((entities: { [id: string]: JournalEntry }, journalEntry: JournalEntry) => {
        return Object.assign(entities, {
          [journalEntry.transactionIdentifier]: journalEntry
        });
      }, {});

      return {
        ids: [ ...journalEntryIds ],
        entities: newJournalEntryEntities,
        startDate: state.startDate,
        endDate: state.endDate,
        loading: false
      };
    }

    default: {
      return state;
    }
  }
}