This repository has been archived by the owner on Apr 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
list-organizations.ts
83 lines (73 loc) · 1.85 KB
/
list-organizations.ts
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
import {BaseCommand} from '../lib'
import {getEnvironment} from '../lib/environments'
import {cli} from 'cli-ux'
const GET_ORGANIZATIONS = `
query GetOrganizations {
organizations {
uid
name
createdBy {
auth0User {
name
email
id
}
}
members {
uid
auth0User {
name
email
}
}
}
}
`
export default class ListOrganizations extends BaseCommand {
static description = 'List Organizations associated with the user'
static examples = [
'$ slash-graphql list-organizations',
]
static flags = {
...BaseCommand.commonFlags,
}
async run() {
const opts = this.parse(ListOrganizations)
const {apiServer, authFile} = getEnvironment(opts.flags.environment)
const token = await this.getAccessToken(apiServer, authFile)
if (!token) {
this.error('Please login with `slash-graphql login` before creating a backend')
}
const {errors, data} = await this.sendGraphQLRequest(apiServer, token, GET_ORGANIZATIONS, {})
if (errors) {
for (const {message} of errors) {
this.error(message)
}
return
}
if (data.organizations === null) {
this.error('Unable to fetch organizations. Please try logging in again with `slash-graphql login`')
}
if (data.organizations.length === 0) {
this.warn('You do not have any organizations.')
}
// this.log('org ', JSON.stringify(data.organizations, null, 2))
cli.table(data.organizations, {
uid: {
minWidth: 7,
},
name: {
minWidth: 10,
},
createdBy: {
get: (org: any) => org.createdBy.auth0User.email,
},
members: {
get: (org: any) => org.members.map((m: any) => m.auth0User.email).join(', '),
},
}, {
printLine: this.log,
...opts.flags, // parsed flags
})
}
}