refactor: improve readability and enable delete account info
This commit is contained in:
parent
4490ca3873
commit
78db9c8765
1 changed files with 8 additions and 8 deletions
|
|
@ -24,14 +24,14 @@ select $1, $2, $3, $4 where $1 not in (select type from user_config)`
|
||||||
function saveAccounts (accounts) {
|
function saveAccounts (accounts) {
|
||||||
return loadAccounts()
|
return loadAccounts()
|
||||||
.then(currentAccounts => {
|
.then(currentAccounts => {
|
||||||
const serviceCodes = _.keys(accounts)
|
const emptySecretFields = _.compose(
|
||||||
const filledAccountInfo = _.map(code => { return { [code]: _.omitBy(_.isEmpty, accounts[code]) } }, serviceCodes)
|
_.map(_.last),
|
||||||
const accountsToSave = _.reduce((result, item) => {
|
_.map(_.split('.')),
|
||||||
var key = Object.keys(item)[0]
|
_.filter(e => _.get(e, accounts) === '')
|
||||||
result[key] = item[key]
|
)(SECRET_FIELDS)
|
||||||
return result
|
const filledAccountInfo = _.mapValues(_.omit(emptySecretFields), accounts)
|
||||||
}, {}, filledAccountInfo)
|
|
||||||
const newAccounts = _.merge(currentAccounts, accountsToSave)
|
const newAccounts = _.merge(currentAccounts, filledAccountInfo)
|
||||||
return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue