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.

56 lines
1.4 KiB

6 years ago
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 list(obj, args, context, info) {
  12. return WIKI.models.pages.query().select(
  13. 'pages.*',
  14. WIKI.models.pages.relatedQuery('users').count().as('userCount')
  15. )
  16. },
  17. async single(obj, args, context, info) {
  18. return WIKI.models.pages.query().findById(args.id)
  19. }
  20. },
  21. PageMutation: {
  22. async create(obj, args, context) {
  23. const page = await WIKI.models.pages.createPage({
  24. ...args,
  25. authorId: context.req.user.id
  26. })
  27. return {
  28. responseResult: graphHelper.generateSuccess('Page created successfully.'),
  29. page
  30. }
  31. },
  32. async delete(obj, args) {
  33. await WIKI.models.groups.query().deleteById(args.id)
  34. return {
  35. responseResult: graphHelper.generateSuccess('Page has been deleted.')
  36. }
  37. },
  38. async update(obj, args, context) {
  39. const page = await WIKI.models.pages.updatePage({
  40. ...args,
  41. authorId: context.req.user.id
  42. })
  43. return {
  44. responseResult: graphHelper.generateSuccess('Page has been updated.'),
  45. page
  46. }
  47. }
  48. },
  49. Page: {
  50. // comments(pg) {
  51. // return pg.$relatedQuery('comments')
  52. // }
  53. }
  54. }