navigation.js 777 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
const graphHelper = require('../../helpers/graph')

/* global WIKI */

module.exports = {
  Query: {
    async navigation() { return {} }
  },
  Mutation: {
    async navigation() { return {} }
  },
  NavigationQuery: {
    async tree(obj, args, context, info) {
14
      return WIKI.models.navigation.getTree()
15 16 17 18 19
    }
  },
  NavigationMutation: {
    async updateTree(obj, args, context) {
      try {
20 21 22
        await WIKI.models.navigation.query().patch({
          config: args.tree
        }).where('key', 'site')
23
        await WIKI.cache.set('nav:sidebar', args.tree, 300)
24

25 26 27 28 29 30 31 32 33
        return {
          responseResult: graphHelper.generateSuccess('Navigation updated successfully')
        }
      } catch (err) {
        return graphHelper.generateError(err)
      }
    }
  }
}