refactor: filter secret empty fields on the front-end

This commit is contained in:
José Oliveira 2021-02-19 18:05:07 +00:00 committed by Josh Harvey
parent 78db9c8765
commit 75629746e7
2 changed files with 16 additions and 9 deletions

View file

@ -22,16 +22,10 @@ const accountsSql = `update user_config set data = $2, valid = $3, schema_versio
insert into user_config (type, data, valid, schema_version)
select $1, $2, $3, $4 where $1 not in (select type from user_config)`
function saveAccounts (accounts) {
console.log('accounts to save ' + JSON.stringify(accounts))
return loadAccounts()
.then(currentAccounts => {
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)
const newAccounts = _.merge(currentAccounts, accounts)
return db.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
})
}