navigation.js 709 B

123456789101112131415161718192021222324252627282930313233
  1. const Model = require('objection').Model
  2. /* global WIKI */
  3. /**
  4. * Navigation model
  5. */
  6. module.exports = class Navigation extends Model {
  7. static get tableName() { return 'navigation' }
  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. config: {type: 'array', items: {type: 'object'}}
  16. }
  17. }
  18. }
  19. static async getTree() {
  20. const navTree = await WIKI.models.navigation.query().findOne('key', 'site')
  21. if (navTree) {
  22. return navTree.config
  23. } else {
  24. WIKI.logger.warn('Site Navigation is missing or corrupted.')
  25. return []
  26. }
  27. }
  28. }