forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-org-owner.js
More file actions
39 lines (35 loc) · 1.04 KB
/
check-org-owner.js
File metadata and controls
39 lines (35 loc) · 1.04 KB
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
39
import { t } from '@lingui/macro'
export const checkOrgOwner =
({ i18n, query, userKey }) =>
async ({ orgId }) => {
const userIdString = `users/${userKey}`
// find affiliation
let affiliationCursor
try {
affiliationCursor = await query`
WITH affiliations, organizations, users
FOR v, e IN 1..1 OUTBOUND ${orgId} affiliations
FILTER e._to == ${userIdString}
RETURN e.owner
`
} catch (err) {
console.error(
`Database error when checking to see if user: ${userKey} is the owner of: ${orgId}: ${err}`,
)
throw new Error(
i18n._(t`Unable to load owner information. Please try again.`),
)
}
let isOrgOwner
try {
isOrgOwner = await affiliationCursor.next()
} catch (err) {
console.error(
`Cursor error when checking to see if user: ${userKey} is the owner of: ${orgId}: ${err}`,
)
throw new Error(
i18n._(t`Unable to load owner information. Please try again.`),
)
}
return isOrgOwner
}