WIPP
This commit is contained in:
parent
7e5515a873
commit
b16d11045c
10 changed files with 368 additions and 550 deletions
43
lib/settings-loader.js
Normal file
43
lib/settings-loader.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
const R = require('ramda')
|
||||
|
||||
const db = require('./db')
|
||||
|
||||
// Note: We won't prematurely optimize by caching yet
|
||||
// This shouldn't really affect performance at these scales
|
||||
|
||||
function load () {
|
||||
return Promise.all([
|
||||
db.one('select data from user_config where type=$1', 'config'),
|
||||
loadAccounts()
|
||||
])
|
||||
.then(function ([data, accounts]) {
|
||||
return {
|
||||
config: data.data,
|
||||
accounts: accounts
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function loadAccounts () {
|
||||
const toFields = fieldArr => R.fromPairs(R.map(r => [r.code, r.value], fieldArr))
|
||||
const toPairs = r => [r.code, toFields(r.fields)]
|
||||
|
||||
return db.oneOrNone('select data from user_config where type=$1', 'accounts')
|
||||
.then(function (data) {
|
||||
if (!data) return {}
|
||||
return R.fromPairs(R.map(toPairs, data.data.accounts))
|
||||
})
|
||||
}
|
||||
|
||||
function settings () {
|
||||
return load()
|
||||
}
|
||||
|
||||
function clear () {
|
||||
// Do nothing, since no caching
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
settings,
|
||||
clear
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue