-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathorganizations.mjs
63 lines (59 loc) · 2.05 KB
/
organizations.mjs
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
import {REMS} from "./index.js";
import {v4 as uuidv4} from "uuid";
import fs from 'fs';
(async function () {
let configuration = null;
let access = null;
if (process.argv[2]) {
console.log(`Configuration file ${process.argv[2]}`);
configuration = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
}
if (process.argv[3]) {
console.log(`Access file ${process.argv[3]}`);
access = JSON.parse(fs.readFileSync(process.argv[3], 'utf8'));
}
if (configuration && access) {
await setup({configuration, access});
} else {
throw new Error('Configuration and Access files missing');
}
})();
async function setup({configuration, access}) {
let rems;
try {
rems = new REMS({
host: configuration.host,
userId: configuration.userId,
key: configuration.api_key,
apis: configuration.apis
});
} catch (e) {
console.log('error instance for organization');
throw new Error(e);
}
let organization;
try {
organization = await rems.getOrganization({id: configuration.organizationId});
if (!organization?.id) {
organization = await rems.organization({
id: configuration.organizationId,
archived: false,
enabled: true,
shortName: access.organization.shortName,
organizationEmail: access.organization.email,
organizationName: access.organization.name,
reviewEmailName: access.organization.reviewEmailName,
ownerId: configuration.userId,
userId: configuration.userId,
userName: configuration.userName,
userEmail: configuration.userEmail,
organizationId: configuration.organizationId
});
} else {
console.log('organization already created', organization['id']);
}
} catch (e) {
console.log('error instance for organization');
throw new Error(e);
}
}