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.
38 lines
763 B
38 lines
763 B
import { Model } from 'objection'
|
|
import { has, reduce, set } from 'lodash-es'
|
|
|
|
/**
|
|
* Settings model
|
|
*/
|
|
export 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'}
|
|
}
|
|
}
|
|
}
|
|
|
|
static get jsonAttributes() {
|
|
return ['value']
|
|
}
|
|
|
|
static async getConfig() {
|
|
const settings = await WIKI.db.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
|
|
}
|
|
}
|
|
}
|