-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Set sourceAccount to null on the io.cozy.contacts.accounts when…
… the io.cozy.accounts is disconnected
- Loading branch information
1 parent
c85155e
commit 7cdc057
Showing
6 changed files
with
59 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,5 +74,6 @@ | |
} | ||
} | ||
}, | ||
"manifest_version": "2" | ||
"manifest_version": "2", | ||
"on_delete_account": "onDeleteAccount.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function getAccountId() { | ||
try { | ||
return process.env.NODE_ENV === 'development' | ||
? 'fakeAccountId' | ||
: JSON.parse(process.env.COZY_FIELDS).account | ||
} catch (err) { | ||
throw new Error(`You must provide 'account' in COZY_FIELDS: ${err.message}`) | ||
} | ||
} | ||
|
||
module.exports = getAccountId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { log } = require('cozy-konnector-libs') | ||
|
||
const getAccountId = require('./helpers/getAccountId') | ||
const CozyUtils = require('./CozyUtils') | ||
|
||
async function onDeleteAccount() { | ||
log('info', 'onDeleteAccount: remove account id from the contact account') | ||
const accountId = getAccountId() | ||
const cozyUtils = new CozyUtils(accountId) | ||
const contactAccount = await cozyUtils.findContactAccount(accountId) | ||
contactAccount.sourceAccount = null | ||
await cozyUtils.client.save(contactAccount) | ||
} | ||
|
||
onDeleteAccount().then( | ||
() => { | ||
log( | ||
'info', | ||
'onDeleteAccount: Successfully marked the io.cozy.contacts.accounts as inactive' | ||
) | ||
}, | ||
err => { | ||
log( | ||
'error', | ||
`onDeleteAccount: An error occured during onDeleteAccount script: ${ | ||
err.message | ||
}` | ||
) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters