forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis-user-admin.js
More file actions
38 lines (33 loc) · 868 Bytes
/
Copy pathis-user-admin.js
File metadata and controls
38 lines (33 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const { GraphQLBoolean } = require('graphql')
const isUserAdmin = {
type: GraphQLBoolean,
description: 'Query used to check if the user has an admin role.',
resolve: async (
_,
args,
{
userId: userKey,
query,
auth: { checkPermission },
loaders: { userLoaderByKey, orgLoaderConnectionsByUserId },
},
) => {
const orgConnections = await orgLoaderConnectionsByUserId({})
const user = await userLoaderByKey.load(userKey)
let permission
for (var i = 0; i < orgConnections.edges.length; i++) {
permission = await checkPermission(
user._id,
'organizations/'.concat(orgConnections.edges[i].node.id),
query,
)
if (permission === 'admin' || permission === 'super_admin') {
return true
}
}
return false
},
}
module.exports = {
isUserAdmin,
}