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.

66 lines
1.6 KiB

  1. const graphHelper = require('../../helpers/graph')
  2. /* global WIKI */
  3. module.exports = {
  4. Query: {
  5. async users() { return {} }
  6. },
  7. Mutation: {
  8. async users() { return {} }
  9. },
  10. UserQuery: {
  11. async list(obj, args, context, info) {
  12. return WIKI.models.users.query()
  13. .select('id', 'email', 'name', 'providerKey', 'isSystem', 'createdAt')
  14. },
  15. async search(obj, args, context, info) {
  16. return WIKI.models.users.query()
  17. .where('email', 'like', `%${args.query}%`)
  18. .orWhere('name', 'like', `%${args.query}%`)
  19. .limit(10)
  20. .select('id', 'email', 'name', 'providerKey', 'createdAt')
  21. },
  22. async single(obj, args, context, info) {
  23. let usr = await WIKI.models.users.query().findById(args.id)
  24. usr.password = ''
  25. usr.tfaSecret = ''
  26. return usr
  27. }
  28. },
  29. UserMutation: {
  30. async create(obj, args) {
  31. try {
  32. await WIKI.models.users.createNewUser(args)
  33. return {
  34. responseResult: graphHelper.generateSuccess('User created successfully')
  35. }
  36. } catch (err) {
  37. return graphHelper.generateError(err)
  38. }
  39. },
  40. delete(obj, args) {
  41. return WIKI.models.users.query().deleteById(args.id)
  42. },
  43. async update(obj, args) {
  44. try {
  45. await WIKI.models.users.updateUser(args)
  46. return {
  47. responseResult: graphHelper.generateSuccess('User created successfully')
  48. }
  49. } catch (err) {
  50. return graphHelper.generateError(err)
  51. }
  52. },
  53. resetPassword(obj, args) {
  54. return false
  55. }
  56. },
  57. User: {
  58. groups(usr) {
  59. return usr.$relatedQuery('groups')
  60. }
  61. }
  62. }