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.

58 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', 'role', 'createdAt', 'updatedAt')
  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', 'role', 'createdAt', 'updatedAt')
  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.query().insertAndFetch(args)
  31. },
  32. delete(obj, args) {
  33. return WIKI.models.users.query().deleteById(args.id)
  34. },
  35. update(obj, args) {
  36. return WIKI.models.users.query().patch({
  37. email: args.email,
  38. name: args.name,
  39. provider: args.provider,
  40. providerId: args.providerId,
  41. role: args.role
  42. }).where('id', args.id)
  43. },
  44. resetPassword(obj, args) {
  45. return false
  46. },
  47. setPassword(obj, args) {
  48. return false
  49. }
  50. },
  51. User: {
  52. groups(usr) {
  53. return usr.getGroups()
  54. }
  55. }
  56. }