fix: removed unnecessary processes from the account loading process

fix: treat an empty response as an error when loading the latest config
This commit is contained in:
Liordino Neto 2020-08-09 15:43:46 -03:00 committed by Josh Harvey
parent 6e356217ae
commit f95deab005

View file

@ -16,9 +16,6 @@ function saveAccounts (accountsToSave) {
}
function loadAccounts () {
const toFields = fieldArr => _.fromPairs(_.map(r => [r.code, r.value], fieldArr))
const toPairs = r => [r.code, toFields(r.fields)]
const sql = `select data
from user_config
where type=$1
@ -28,10 +25,7 @@ function loadAccounts () {
limit 1`
return db.oneOrNone(sql, ['accounts', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => {
if (!row) return {}
return _.fromPairs(_.map(toPairs, row.data.accounts))
})
.then(row => row ? row.data.accounts : null)
}
function saveConfig (config) {
@ -60,12 +54,12 @@ function loadLatestConfig () {
and valid
order by id desc
limit 1`
return db.oneOrNone(sql, ['config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.one(sql, ['config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => !row ? {} : row.data.config)
.catch(err => {
if (err.name === 'QueryResultError') {
throw new Error('lamassu-server is not configured')
throw new Error('No config was found')
}
throw err