forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis-user-super-admin.js
More file actions
33 lines (29 loc) · 892 Bytes
/
is-user-super-admin.js
File metadata and controls
33 lines (29 loc) · 892 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
import { GraphQLBoolean } from 'graphql'
import { t } from '@lingui/macro'
export const isUserSuperAdmin = {
type: GraphQLBoolean,
description: 'Query used to check if the user has a super admin role.',
resolve: async (_, __, { i18n, query, userKey, auth: { userRequired } }) => {
const user = await userRequired()
let userAdmin
try {
userAdmin = await query`
FOR v, e IN 1..1 INBOUND ${user._id} affiliations
FILTER e.permission == "super_admin"
LIMIT 1
RETURN e.permission
`
} catch (err) {
console.error(
`Database error occurred when user: ${userKey} was seeing if they were a super admin, err: ${err}`,
)
throw new Error(
i18n._(t`Unable to verify if user is a super admin, please try again.`),
)
}
if (userAdmin.count > 0) {
return true
}
return false
},
}