user.js 1.38 KB
Newer Older
NGPixel's avatar
NGPixel committed
1

2
/* global WIKI */
NGPixel's avatar
NGPixel committed
3 4

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