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.

51 lines
1.0 KiB

  1. /* global WIKI */
  2. const gql = require('graphql')
  3. module.exports = {
  4. Query: {
  5. files(obj, args, context, info) {
  6. return WIKI.models.File.findAll({ where: args })
  7. }
  8. },
  9. Mutation: {
  10. uploadFile(obj, args) {
  11. // todo
  12. return WIKI.models.File.create(args)
  13. },
  14. deleteFile(obj, args) {
  15. return WIKI.models.File.destroy({
  16. where: {
  17. id: args.id
  18. },
  19. limit: 1
  20. })
  21. },
  22. renameFile(obj, args) {
  23. return WIKI.models.File.update({
  24. filename: args.filename
  25. }, {
  26. where: { id: args.id }
  27. })
  28. },
  29. moveFile(obj, args) {
  30. return WIKI.models.File.findById(args.fileId).then(fl => {
  31. if (!fl) {
  32. throw new gql.GraphQLError('Invalid File ID')
  33. }
  34. return WIKI.models.Folder.findById(args.folderId).then(fld => {
  35. if (!fld) {
  36. throw new gql.GraphQLError('Invalid Folder ID')
  37. }
  38. return fl.setFolder(fld)
  39. })
  40. })
  41. }
  42. },
  43. File: {
  44. folder(fl) {
  45. return fl.getFolder()
  46. }
  47. }
  48. }