How to use the cozy-client.Q function in cozy-client

To help you get started, we’ve selected a few cozy-client 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 / groups / services.js View on Github external
export const purgeAutoGroups = async ({ client }) => {
  const { data: groups } = await client.query(Q(GROUP_DOCTYPE, { limit: null }))
  let autogroups = groups.filter(isAutoGroup)

  autogroups = autogroups.map(x => omit(x, '_type'))
  const col = client.collection(GROUP_DOCTYPE)
  await col.destroyAll(autogroups)
  log('info', `Destroyed ${autogroups.length} autogroups`)
}
github cozy / cozy.github.io / en / cozy-banks / src / ducks / notifications / services.js View on Github external
export const fetchGroups = async client => {
  const groups = await client.query(Q(GROUP_DOCTYPE))
  return groups
}
github cozy / cozy.github.io / en / cozy-banks / src / ducks / budgetAlerts / index.js View on Github external
const fetchGroup = async (client, groupId) => {
  const { data: group } = await client.query(Q(GROUP_DOCTYPE).getById(groupId))
  return group
}
github cozy / cozy.github.io / en / cozy-banks / src / ducks / account / services.js View on Github external
export const unlinkMyselfFromAccounts = async ({ client }) => {
  let myself

  try {
    myself = await fetchMyself(client)
  } catch (err) {
    log('error', 'Error while fetching myself contact')
    log('error', err)
    return
  }

  const accounts = await client.queryAll(Q(ACCOUNT_DOCTYPE))

  for (const account of accounts) {
    const currentOwners = get(account, 'relationships.owners.data', [])
    const ownersWithoutMyself = currentOwners.filter(
      owner => owner._id !== myself._id
    )

    set(account, 'relationships.owners.data', ownersWithoutMyself)

    await client.save(account)
  }

  const settings = await fetchSettings(client)
  settings.linkMyselfToAccounts.processedAccounts = []
  await updateSettings(client, settings)
github cozy / cozy.github.io / en / cozy-banks / src / doctypes.js View on Github external
query: () =>
    Q(RECURRENCE_DOCTYPE)
      .where({ _id: { $gt: null } })
      .sortBy([{ latestDate: 'desc' }]),
  as: 'recurrence',
github cozy / cozy.github.io / en / cozy-banks / src / ducks / categorization / services.js View on Github external
export const fetchTransactionsToCategorize = async client => {
  const transactions = await client.queryAll(
    Q(TRANSACTION_DOCTYPE).where({ toCategorize: true })
  )
  return transactions
}
github cozy / cozy.github.io / en / cozy-banks / src / ducks / groups / services.js View on Github external
export const createAutoGroups = async ({ client }) => {
  const settings = await fetchSettings(client)
  const groups = await client.queryAll(Q(GROUP_DOCTYPE))
  const accounts = await client.queryAll(Q(ACCOUNT_DOCTYPE))

  const alreadyProcessed = new Set(settings.autogroups.processedAccounts)

  log(
    'info',
    `Number of accounts already processed by autogroups: ${alreadyProcessed.size}`
  )
  const accountsToProcess = accounts.filter(
    account => !alreadyProcessed.has(account._id)
  )

  if (accountsToProcess.length === 0) {
    log('info', 'No accounts to process for autogroups, bailing out.')
    return
  }
github cozy / cozy.github.io / en / cozy-banks / src / ducks / budgetAlerts / CategoryBudgetNotificationView.js View on Github external
const fetchDoctypeById = async (client, doctype) => {
  const { data } = await client.query(Q(doctype))
  return keyBy(data, x => x._id)
}