feat: user profile fetch info + groups

This commit is contained in:
NGPixel
2020-03-30 01:30:10 -04:00
committed by Nicolas Giard
parent 8ea699ac7a
commit c7f3c9d908
6 changed files with 498 additions and 24 deletions

View File

@@ -26,6 +26,24 @@ module.exports = {
usr.password = ''
usr.tfaSecret = ''
return usr
},
async profile (obj, args, context, info) {
if (!context.req.user || context.req.user.id < 1 || context.req.user.id === 2) {
throw new WIKI.Error.AuthRequired()
}
const usr = await WIKI.models.users.query().findById(context.req.user.id)
if (!usr.isActive) {
throw new WIKI.Error.AuthAccountBanned()
}
const usrGroups = await usr.$relatedQuery('groups')
return {
...usr,
password: '',
providerKey: '',
tfaSecret: '',
lastLoginOn: '1970-01-01',
groups: usrGroups.map(g => g.name)
}
}
},
UserMutation: {