From 78db9c87650c2de31432fbe778c09492391e5a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Wed, 17 Feb 2021 22:03:36 +0000 Subject: [PATCH] refactor: improve readability and enable delete account info --- lib/new-settings-loader.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/new-settings-loader.js b/lib/new-settings-loader.js index a1cbd243..3e535ca6 100644 --- a/lib/new-settings-loader.js +++ b/lib/new-settings-loader.js @@ -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]) }) }