settings.js 792 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. const Model = require('objection').Model
  2. const _ = require('lodash')
  3. /* global WIKI */
  4. /**
  5. * Settings model
  6. */
  7. module.exports = class Setting extends Model {
  8. static get tableName() { return 'settings' }
  9. static get idColumn() { return 'key' }
  10. static get jsonSchema () {
  11. return {
  12. type: 'object',
  13. required: ['key'],
  14. properties: {
  15. key: {type: 'string'}
  16. }
  17. }
  18. }
  19. static get jsonAttributes() {
  20. return ['value']
  21. }
  22. static async getConfig() {
  23. const settings = await WIKI.models.settings.query()
  24. if (settings.length > 0) {
  25. return _.reduce(settings, (res, val, key) => {
  26. _.set(res, val.key, (_.has(val.value, 'v')) ? val.value.v : val.value)
  27. return res
  28. }, {})
  29. } else {
  30. return false
  31. }
  32. }
  33. }