forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorganization.js
More file actions
147 lines (144 loc) · 4.22 KB
/
Copy pathorganization.js
File metadata and controls
147 lines (144 loc) · 4.22 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { t } from '@lingui/macro'
import {
GraphQLBoolean,
GraphQLInt,
GraphQLObjectType,
GraphQLString,
} from 'graphql'
import {
connectionArgs,
connectionDefinitions,
globalIdField,
} from 'graphql-relay'
import { affiliationConnection } from '../../affiliation/objects'
import { organizationSummaryType } from './organization-summary'
import { Acronym, Slug } from '../../scalars'
import { nodeInterface } from '../../node'
import { domainConnection } from '../../domain/objects'
export const organizationType = new GraphQLObjectType({
name: 'Organization',
fields: () => ({
id: globalIdField('organizations'),
acronym: {
type: Acronym,
description: 'The organizations acronym.',
resolve: ({ acronym }) => acronym,
},
name: {
type: GraphQLString,
description: 'The full name of the organization.',
resolve: ({ name }) => name,
},
slug: {
type: Slug,
description: 'Slugified name of the organization.',
resolve: ({ slug }) => slug,
},
zone: {
type: GraphQLString,
description: 'The zone which the organization belongs to.',
resolve: ({ zone }) => zone,
},
sector: {
type: GraphQLString,
description: 'The sector which the organization belongs to.',
resolve: ({ sector }) => sector,
},
country: {
type: GraphQLString,
description: 'The country in which the organization resides.',
resolve: ({ country }) => country,
},
province: {
type: GraphQLString,
description: 'The province in which the organization resides.',
resolve: ({ province }) => province,
},
city: {
type: GraphQLString,
description: 'The city in which the organization resides.',
resolve: ({ city }) => city,
},
verified: {
type: GraphQLBoolean,
description: 'Wether the organization is a verified organization.',
resolve: ({ verified }) => verified,
},
summaries: {
type: organizationSummaryType,
description:
'Summaries based on scan types that are preformed on the given organizations domains.',
resolve: ({ summaries }) => summaries,
},
domainCount: {
type: GraphQLInt,
description: 'The number of domains associated with this organization.',
resolve: ({ domainCount }) => domainCount,
},
domains: {
type: domainConnection.connectionType,
description: 'The domains which are associated with this organization.',
args: {
ownership: {
type: GraphQLBoolean,
description:
'Limit domains to those that belong to an organization that has ownership.',
},
...connectionArgs,
},
resolve: async (
{ _id },
args,
{ loaders: { domainLoaderConnectionsByOrgId } },
) => {
const connections = await domainLoaderConnectionsByOrgId({
orgId: _id,
...args,
})
return connections
},
},
affiliations: {
type: affiliationConnection.connectionType,
description: 'Organization affiliations to various users.',
args: connectionArgs,
resolve: async (
{ _id },
args,
{
i18n,
auth: { checkPermission },
loaders: { affiliationLoaderByOrgId },
},
) => {
const permission = await checkPermission({ orgId: _id })
if (permission === 'admin' || permission === 'super_admin') {
const affiliations = await affiliationLoaderByOrgId({
orgId: _id,
...args,
})
return affiliations
}
throw new Error(
i18n._(
t`Cannot query affiliations on organization without admin permission or higher.`,
),
)
},
},
}),
interfaces: [nodeInterface],
description:
'Organization object containing information for a given Organization.',
})
export const organizationConnection = connectionDefinitions({
name: 'Organization',
nodeType: organizationType,
connectionFields: () => ({
totalCount: {
type: GraphQLInt,
description: 'The total amount of organizations the user has access to.',
resolve: ({ totalCount }) => totalCount,
},
}),
})