settings.mjs 763 B

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