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) {
|
||||
return loadAccounts()
|
||||
.then(currentAccounts => {
|
||||
const serviceCodes = _.keys(accounts)
|
||||
const filledAccountInfo = _.map(code => { return { [code]: _.omitBy(_.isEmpty, accounts[code]) } }, serviceCodes)
|
||||
const accountsToSave = _.reduce((result, item) => {
|
||||
var key = Object.keys(item)[0]
|
||||
result[key] = item[key]
|
||||
return result
|
||||
}, {}, filledAccountInfo)
|
||||
const newAccounts = _.merge(currentAccounts, accountsToSave)
|
||||
const emptySecretFields = _.compose(
|
||||
_.map(_.last),
|
||||
_.map(_.split('.')),
|
||||
_.filter(e => _.get(e, accounts) === '')
|
||||
)(SECRET_FIELDS)
|
||||
const filledAccountInfo = _.mapValues(_.omit(emptySecretFields), accounts)
|
||||
|
||||
const newAccounts = _.merge(currentAccounts, filledAccountInfo)
|
||||
return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue