How to use the cozy-doctypes.BankTransaction.queryAll 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 / ducks / notifications / LateHealthReimbursement / index.js View on Github external
async getTransactions() {
    const DATE_FORMAT = 'YYYY-MM-DD'
    const today = new Date()
    const lt = formatDate(subDays(today, this.interval), DATE_FORMAT)
    const gt = formatDate(subMonths(lt, 6), DATE_FORMAT)

    log('info', `Fetching transactions between ${gt} and ${lt}`)
    const transactionsInDateRange = await BankTransaction.queryAll({
      date: {
        $gt: gt,
        $lt: lt
      }
    })
    log(
      'info',
      `${transactionsInDateRange.length} fetched transactions between ${gt} and ${lt}`
    )

    const healthExpenses = transactionsInDateRange.filter(isHealthExpense)

    log('info', `${healthExpenses.length} are health expenses`)

    const billIds = getReimbursementBillIds(healthExpenses)
    const bills = await Bill.getAll(billIds)