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.

83 lines
1.9 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. const graphHelper = require('../../helpers/graph')
  2. /* global WIKI */
  3. module.exports = {
  4. Query: {
  5. async pages() { return {} }
  6. },
  7. Mutation: {
  8. async pages() { return {} }
  9. },
  10. PageQuery: {
  11. async history(obj, args, context, info) {
  12. return WIKI.models.pageHistory.getHistory({
  13. pageId: args.id,
  14. offsetPage: args.offsetPage || 0,
  15. offsetSize: args.offsetSize || 100
  16. })
  17. },
  18. async search (obj, args, context) {
  19. if (WIKI.data.searchEngine) {
  20. return WIKI.data.searchEngine.query(args.query, args)
  21. } else {
  22. return {
  23. results: [],
  24. suggestions: [],
  25. totalHits: 0
  26. }
  27. }
  28. },
  29. async list (obj, args, context, info) {
  30. return WIKI.models.pages.query().column([
  31. 'id',
  32. 'path',
  33. { locale: 'localeCode' },
  34. 'title',
  35. 'description',
  36. 'isPublished',
  37. 'isPrivate',
  38. 'privateNS',
  39. 'contentType',
  40. 'createdAt',
  41. 'updatedAt'
  42. ])
  43. }
  44. },
  45. PageMutation: {
  46. async create(obj, args, context) {
  47. const page = await WIKI.models.pages.createPage({
  48. ...args,
  49. authorId: context.req.user.id
  50. })
  51. return {
  52. responseResult: graphHelper.generateSuccess('Page created successfully.'),
  53. page
  54. }
  55. },
  56. async delete(obj, args, context) {
  57. await WIKI.models.pages.deletePage({
  58. ...args,
  59. authorId: context.req.user.id
  60. })
  61. return {
  62. responseResult: graphHelper.generateSuccess('Page has been deleted.')
  63. }
  64. },
  65. async update(obj, args, context) {
  66. const page = await WIKI.models.pages.updatePage({
  67. ...args,
  68. authorId: context.req.user.id
  69. })
  70. return {
  71. responseResult: graphHelper.generateSuccess('Page has been updated.'),
  72. page
  73. }
  74. }
  75. },
  76. Page: {
  77. // comments(pg) {
  78. // return pg.$relatedQuery('comments')
  79. // }
  80. }
  81. }