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.
49 lines
1007 B
49 lines
1007 B
const Model = require('objection').Model
|
|
const _ = require('lodash')
|
|
|
|
/* global WIKI */
|
|
|
|
/**
|
|
* Settings model
|
|
*/
|
|
module.exports = class Setting extends Model {
|
|
static get tableName() { return 'settings' }
|
|
static get idColumn() { return 'key' }
|
|
|
|
static get jsonSchema () {
|
|
return {
|
|
type: 'object',
|
|
required: ['key'],
|
|
|
|
properties: {
|
|
key: {type: 'string'},
|
|
createdAt: {type: 'string'},
|
|
updatedAt: {type: 'string'}
|
|
}
|
|
}
|
|
}
|
|
|
|
static get jsonAttributes() {
|
|
return ['value']
|
|
}
|
|
|
|
$beforeUpdate() {
|
|
this.updatedAt = new Date().toISOString()
|
|
}
|
|
$beforeInsert() {
|
|
this.updatedAt = new Date().toISOString()
|
|
}
|
|
|
|
static async getConfig() {
|
|
const settings = await WIKI.models.settings.query()
|
|
if (settings.length > 0) {
|
|
return _.reduce(settings, (res, val, key) => {
|
|
_.set(res, val.key, (_.has(val.value, 'v')) ? val.value.v : val.value)
|
|
return res
|
|
}, {})
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
}
|