This commit is contained in:
Josh Harvey 2016-12-08 17:56:50 +02:00
parent df5d9cac89
commit a375adb8b9
3 changed files with 516 additions and 496 deletions

View file

@ -12,6 +12,14 @@ function load (versionId) {
}))
}
function loadLatest (versionId) {
return Promise.all([loadLatestConfig(), loadAccounts()])
.then(([config, accounts]) => ({
config,
accounts
}))
}
function loadConfig (versionId) {
const sql = `select data
from user_config
@ -21,6 +29,17 @@ function loadConfig (versionId) {
.then(row => row ? row.data.config : [])
}
function loadLatestConfig () {
const sql = `select data
from user_config
where type=$1
order by versionId desc
limit 1`
return db.oneOrNone(sql, ['config'])
.then(row => row ? row.data.config : [])
}
function loadAccounts () {
const toFields = fieldArr => R.fromPairs(R.map(r => [r.code, r.value], fieldArr))
const toPairs = r => [r.code, toFields(r.fields)]
@ -45,5 +64,6 @@ module.exports = {
settings,
loadConfig,
load,
loadLatest,
save
}