How to use cozy-doctypes - 10 common examples

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 / service.js View on Github external
export const runService = service => {
  assertEnvVar('COZY_URL')
  assertEnvVar('COZY_CREDENTIALS')

  const client = new CozyClient({
    uri: process.env.COZY_URL.trim(),
    schema,
    token: process.env.COZY_CREDENTIALS.trim()
  })
  Document.registerClient(client)

  return service({ client }).catch(e => {
    // eslint-disable-next-line no-console
    console.error(e)
    process.exit(1)
  })
}
github cozy / cozy.github.io / en / cozy-banks / scripts / visualizer / src / server / index.js View on Github external
/**
 * Visualizer to see links between transactions and bills.
 *
 * Launch with `cozy-run-dev visualizer/index.js`
 */
const Linker = require('ducks/billsMatching/Linker/Linker').default
const { cozyClient } = require('cozy-konnector-libs')
const { Document } = require('cozy-doctypes')
const { Bill } = require('models')
const path = require('path')

// TODO Find out why our models parent class and Document from cozy-doctypes are different
Document.registerClient(cozyClient)
Bill.registerClient(cozyClient)

class DryLinker extends Linker {
  commitChanges() {
    return Promise.resolve()
  }
}

const generate = async options => {
  const bills = await Bill.fetchAll()

  const linker = new DryLinker(cozyClient)
  const results = await linker.linkBillsToOperations(bills, undefined, options)
  return results
}
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
github cozy / cozy.github.io / en / cozy-banks / src / ducks / notifications / DelayedDebit / index.js View on Github external
async findMatchingRules() {
    const accounts = await BankAccount.fetchAll()
    const accountsById = keyBy(accounts, getDocumentId)
    const matchingRules = this.rules
      .map(this.makeRuleMatcher(accountsById))
      .filter(Boolean)

    return matchingRules
  }
github cozy / cozy.github.io / en / cozy-banks / src / ducks / notifications / LateHealthReimbursement / index.js View on Github external
getAccounts(transactions) {
    const accountIds = uniq(
      transactions.map(transaction => transaction.account)
    )
    return BankAccount.getAll(accountIds)
  }
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)
github cozy / cozy-ui / react / ContactsList / Contacts / ContactName.jsx View on Github external
const {
    givenName: firstname = contact.fullname,
    familyName: lastname = ''
  } = name

  return (
    <div>
      <span>{firstname}</span>
      &nbsp;
      <span>{lastname}</span>
    </div>
  )
}

ContactName.propTypes = {
  contact: Contact.propType.isRequired
}

export default ContactName
github cozy / cozy-ui / react / ContactsList / ContactRow.jsx View on Github external
},
        className
      )}
      onClick={() =&gt; onClick(contact)}
      {...rest}
    &gt;
      
      {!isMobile &amp;&amp; }
      {!isMobile &amp;&amp; }
      {!isMobile &amp;&amp; }
    
  )
}

ContactRow.propTypes = {
  contact: Contact.propType.isRequired
}

export default withBreakpoints()(ContactRow)
github cozy / cozy-ui / react / ContactsList / Contacts / ContactIdentity.jsx View on Github external
return (
    <div>
      
      
      {isMyself &amp;&amp; }
    </div>
  )
}

ContactIdentity.propTypes = {
  contact: Contact.propType.isRequired
}

export default ContactIdentity
github cozy / cozy.github.io / en / cozy-banks / src / targets / services / onOperationOrBillCreate.js View on Github external
const main = async () => {
  attachProcessEventHandlers()
  const client = CozyClient.fromEnv(process.env)
  Document.registerClient(client)
  const options = await getOptions(cozyClient)
  log('info', 'Options:')
  log('info', JSON.stringify(options))
  await onOperationOrBillCreate(client, options)
}