How to use the cozy-doctypes.BankAccountStats.fetchAll function in cozy-doctypes

To help you get started, we’ve selected a few cozy-doctypes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cozy / cozy.github.io / en / cozy-banks / src / targets / services / stats.js View on Github external
const computeBankAccountStats = async () => {
  log('info', 'Fetching settings...')
  let setting = await Settings.fetchWithDefault()

  // The flag is needed to use local model when getting a transaction category ID
  flag('local-model-override', setting.community.localModelOverride.enabled)

  const stats = await BankAccountStats.fetchAll()
  const statsByAccountId = keyBy(
    stats,
    stat => stat.relationships.account.data._id
  )

  const period = getPeriod()
  const transactions = await fetchTransactionsForPeriod(period)

  log(
    'info',
    `${transactions.length} transactions between ${period.start} and ${period.end}`
  )

  const transactionsByAccount = groupBy(
    transactions,
    transaction => transaction.account