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.

52 lines
1.3 KiB

  1. const graphHelper = require('../../helpers/graph')
  2. /* global WIKI */
  3. module.exports = {
  4. Query: {
  5. async navigation () { return {} }
  6. },
  7. Mutation: {
  8. async navigation () { return {} }
  9. },
  10. NavigationQuery: {
  11. async tree (obj, args, context, info) {
  12. return WIKI.models.navigation.getTree({ cache: false, locale: 'all', bypassAuth: true })
  13. },
  14. config (obj, args, context, info) {
  15. return WIKI.config.nav
  16. }
  17. },
  18. NavigationMutation: {
  19. async updateTree (obj, args, context) {
  20. try {
  21. await WIKI.models.navigation.query().patch({
  22. config: args.tree
  23. }).where('key', 'site')
  24. for (const tree of args.tree) {
  25. await WIKI.cache.set(`nav:sidebar:${tree.locale}`, tree.items, 300)
  26. }
  27. return {
  28. responseResult: graphHelper.generateSuccess('Navigation updated successfully')
  29. }
  30. } catch (err) {
  31. return graphHelper.generateError(err)
  32. }
  33. },
  34. async updateConfig (obj, args, context) {
  35. try {
  36. WIKI.config.nav = {
  37. mode: args.mode
  38. }
  39. await WIKI.configSvc.saveToDb(['nav'])
  40. return {
  41. responseResult: graphHelper.generateSuccess('Navigation config updated successfully')
  42. }
  43. } catch (err) {
  44. return graphHelper.generateError(err)
  45. }
  46. }
  47. }
  48. }