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.

61 lines
1.4 KiB

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