Exemplo n.º 1
0
) => (dispatch, getState) => {
  const state = getState()
  const collection = getCollection(state, COLLECTION_NAME)
  if (
    collection &&
    collection.fetchStatus === 'loaded' &&
    collection.hasMore === false
  ) {
    return
  }
  const action = fetchCollection(COLLECTION_NAME, TRANSACTION_DOCTYPE, {
    sort: { date: 'desc' },
    descending: true,
    limit: 100,
    fields: [
      'date',
      'manualCategoryId',
      'automaticCategoryId',
      'currency',
      'amount',
      'label',
      'bills',
      'account'
    ],
    ...options
  })
  const originalPromise = action.promise
  action.promise = (client, dispatch) => {
    return originalPromise(client)
      .then(res => parseTransactions(dispatch, res))
      .then(res => {
        if (onFetch) {
          onFetch(dispatch, res)
        }
        if (firstFetch) {
          firstFetch = false

          // We must defer the filter after transactions
          // have been correctly stored
          defer(() => {
            dispatch(addFilterForMostRecentTransactions())
          })
        }
        return res
      })
  }

  return dispatch(action)
})
Exemplo n.º 2
0
export const getTransactions = state => getCollection(state, COLLECTION_NAME)
Exemplo n.º 3
0
export const getTransactions = state => {
  const col = getCollection(state, 'transactions')
  return (col && col.data) || []
}
Exemplo n.º 4
0
export const getGroups = state => {
  const col = getCollection(state, 'groups')
  return (col && col.data) || []
}
Exemplo n.º 5
0
export const getAccounts = state => {
  const col = getCollection(state, 'accounts')
  return (col && col.data) || []
}