mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
971 B
46 lines
971 B
7 years ago
|
const Model = require('objection').Model
|
||
7 years ago
|
const _ = require('lodash')
|
||
|
|
||
|
/* global WIKI */
|
||
7 years ago
|
|
||
|
/**
|
||
|
* Settings model
|
||
|
*/
|
||
7 years ago
|
module.exports = class Setting extends Model {
|
||
7 years ago
|
static get tableName() { return 'settings' }
|
||
|
|
||
|
static get jsonSchema () {
|
||
|
return {
|
||
|
type: 'object',
|
||
|
required: ['key', 'value'],
|
||
|
|
||
|
properties: {
|
||
|
id: {type: 'integer'},
|
||
|
key: {type: 'string'},
|
||
|
value: {type: 'object'},
|
||
|
createdAt: {type: 'string'},
|
||
|
updatedAt: {type: 'string'}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$beforeUpdate() {
|
||
|
this.updatedAt = new Date().toISOString()
|
||
|
}
|
||
|
$beforeInsert() {
|
||
|
this.updatedAt = new Date().toISOString()
|
||
|
}
|
||
7 years ago
|
|
||
|
static async getConfig() {
|
||
7 years ago
|
const settings = await WIKI.models.settings.query()
|
||
7 years ago
|
if (settings.length > 0) {
|
||
|
return _.reduce(settings, (res, val, key) => {
|
||
|
_.set(res, val.key, (val.value.v) ? val.value.v : val.value)
|
||
|
return res
|
||
|
}, {})
|
||
|
} else {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
7 years ago
|
}
|