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
2 years ago
|
import { Model } from 'objection'
|
||
|
import { has, reduce, set } from 'lodash-es'
|
||
7 years ago
|
|
||
7 years ago
|
/**
|
||
|
* Settings model
|
||
|
*/
|
||
2 years ago
|
export class Setting extends Model {
|
||
7 years ago
|
static get tableName() { return 'settings' }
|
||
6 years ago
|
static get idColumn() { return 'key' }
|
||
7 years ago
|
|
||
|
static get jsonSchema () {
|
||
|
return {
|
||
|
type: 'object',
|
||
6 years ago
|
required: ['key'],
|
||
7 years ago
|
|
||
|
properties: {
|
||
3 years ago
|
key: {type: 'string'}
|
||
7 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
6 years ago
|
static get jsonAttributes() {
|
||
|
return ['value']
|
||
|
}
|
||
|
|
||
7 years ago
|
static async getConfig() {
|
||
2 years ago
|
const settings = await WIKI.db.settings.query()
|
||
7 years ago
|
if (settings.length > 0) {
|
||
2 years ago
|
return reduce(settings, (res, val, key) => {
|
||
|
set(res, val.key, (has(val.value, 'v')) ? val.value.v : val.value)
|
||
7 years ago
|
return res
|
||
|
}, {})
|
||
|
} else {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
7 years ago
|
}
|