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
151 lines (149 loc) · 4.52 KB
/
organization.js
File metadata and controls
151 lines (149 loc) · 4.52 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
148
149
150
151
import { t } from '@lingui/macro'
import {
GraphQLBoolean,
GraphQLInt,
GraphQLObjectType,
GraphQLString,
} from 'graphql'
import { connectionArgs, globalIdField } from 'graphql-relay'
import { organizationSummaryType } from './organization-summary'
import { nodeInterface } from '../../node'
import { Acronym, Slug } from '../../scalars'
import { affiliationUserOrder } from '../../affiliation/inputs'
import { affiliationConnection } from '../../affiliation/objects'
import { domainOrder } from '../../domain/inputs'
import { domainConnection } from '../../domain/objects'
export const organizationType = new GraphQLObjectType({
name: 'Organization',
fields: () => ({
id: globalIdField('organization'),
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: 'Whether 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: {
orderBy: {
type: domainOrder,
description: 'Ordering options for domain connections.',
},
ownership: {
type: GraphQLBoolean,
description:
'Limit domains to those that belong to an organization that has ownership.',
},
search: {
type: GraphQLString,
description: 'String used to search for domains.',
},
...connectionArgs,
},
resolve: async (
{ _id },
args,
{ loaders: { loadDomainConnectionsByOrgId } },
) => {
const connections = await loadDomainConnectionsByOrgId({
orgId: _id,
...args,
})
return connections
},
},
affiliations: {
type: affiliationConnection.connectionType,
description: 'Organization affiliations to various users.',
args: {
orderBy: {
type: affiliationUserOrder,
description: 'Ordering options for affiliation connections.',
},
search: {
type: GraphQLString,
description: 'String used to search for affiliated users.',
},
...connectionArgs,
},
resolve: async (
{ _id },
args,
{
i18n,
auth: { checkPermission },
loaders: { loadAffiliationConnectionsByOrgId },
},
) => {
const permission = await checkPermission({ orgId: _id })
if (permission === 'admin' || permission === 'super_admin') {
const affiliations = await loadAffiliationConnectionsByOrgId({
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.',
})