All about user login
Not runnable at the moment
This commit is contained in:
parent
fbb8f5799e
commit
d79bbad575
49 changed files with 1554 additions and 686 deletions
44
models/settings.js
Normal file
44
models/settings.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
'use strict';
|
||||
|
||||
'use strict';
|
||||
|
||||
const knex = require('../lib/knex');
|
||||
const tools = require('../lib/tools');
|
||||
|
||||
async function get(keyOrKeys) {
|
||||
let keys;
|
||||
if (!Array.isArray(keyOrKeys)) {
|
||||
keys = [ keys ];
|
||||
} else {
|
||||
keys = keyOrKeys;
|
||||
}
|
||||
|
||||
keys = keys.map(key => tools.toDbKey(key));
|
||||
|
||||
const result = await knex('settings').whereIn('key', keys);
|
||||
|
||||
const settings = {};
|
||||
for (const key of keys) {
|
||||
settings[tools.fromDbKey(key)] = result[key];
|
||||
}
|
||||
|
||||
if (!Array.isArray(keyOrKeys)) {
|
||||
return settings[keyOrKeys];
|
||||
} else {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
|
||||
async function set(key, value) {
|
||||
try {
|
||||
await knex('settings').insert({key, value});
|
||||
} catch (err) {
|
||||
await knex('settings').where('key', key).update('value', value);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
get,
|
||||
set
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue