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 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)
})
}
/**
* 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
}
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
async findMatchingRules() {
const accounts = await BankAccount.fetchAll()
const accountsById = keyBy(accounts, getDocumentId)
const matchingRules = this.rules
.map(this.makeRuleMatcher(accountsById))
.filter(Boolean)
return matchingRules
}
getAccounts(transactions) {
const accountIds = uniq(
transactions.map(transaction => transaction.account)
)
return BankAccount.getAll(accountIds)
}
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)
const {
givenName: firstname = contact.fullname,
familyName: lastname = ''
} = name
return (
<div>
<span>{firstname}</span>
<span>{lastname}</span>
</div>
)
}
ContactName.propTypes = {
contact: Contact.propType.isRequired
}
export default ContactName
},
className
)}
onClick={() => onClick(contact)}
{...rest}
>
{!isMobile && }
{!isMobile && }
{!isMobile && }
)
}
ContactRow.propTypes = {
contact: Contact.propType.isRequired
}
export default withBreakpoints()(ContactRow)
return (
<div>
{isMyself && }
</div>
)
}
ContactIdentity.propTypes = {
contact: Contact.propType.isRequired
}
export default ContactIdentity
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)
}