Newer
Older

Bastien DUMONT
committed
const { log, updateOrCreate } = require('cozy-konnector-libs')
const { isLocal } = require('../helpers/env')
const cozyClient = require('cozy-konnector-libs/dist/libs/cozyclient')
async function saveAccountData(accountId, accountData) {
log('info', `saveAccountData: ${accountId}`)
let account = await getAccount(accountId)
account = await updateOrCreate(
[{ ...account, data: accountData }],
'io.cozy.accounts'
)
return account
}

Bastien DUMONT
committed
log('info', `getAccount: ${accountId}`)
const accounts = await cozyClient.data.findAll('io.cozy.accounts')
const body = await cozyClient.fetchJSON(
'GET',
`/data/io.cozy.accounts/${accountId}?rev=${accountRev}`
)
log('info', `getAccount: ${body}`)

Bastien DUMONT
committed
return accounts.filter(account =>
isLocal() ? account._id === accountId : account.account_type === accountId
)[0]
}
module.exports = { getAccount, saveAccountData }