Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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`)
}
export const fetchGroups = async client => {
const groups = await client.query(Q(GROUP_DOCTYPE))
return groups
}
const fetchGroup = async (client, groupId) => {
const { data: group } = await client.query(Q(GROUP_DOCTYPE).getById(groupId))
return group
}
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)
query: () => Q(GROUP_DOCTYPE),
as: 'groups',
query: () =>
Q(RECURRENCE_DOCTYPE)
.where({ _id: { $gt: null } })
.sortBy([{ latestDate: 'desc' }]),
as: 'recurrence',
export const fetchTransactionsToCategorize = async client => {
const transactions = await client.queryAll(
Q(TRANSACTION_DOCTYPE).where({ toCategorize: true })
)
return transactions
}
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
}
const fetchDoctypeById = async (client, doctype) => {
const { data } = await client.query(Q(doctype))
return keyBy(data, x => x._id)
}
query: () => Q(SETTINGS_DOCTYPE),
as: 'settings',