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:
parent
6e356217ae
commit
f95deab005
1 changed files with 4 additions and 10 deletions
|
|
@ -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) {
|
||||
|
|
@ -61,11 +55,11 @@ function loadLatestConfig () {
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue