forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-super-admin-org.js
More file actions
80 lines (74 loc) · 1.83 KB
/
create-super-admin-org.js
File metadata and controls
80 lines (74 loc) · 1.83 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
const {
SA_ORG_EN_SLUG,
SA_ORG_EN_ACRONYM,
SA_ORG_EN_NAME,
SA_ORG_EN_ZONE,
SA_ORG_EN_SECTOR,
SA_ORG_EN_COUNTRY,
SA_ORG_EN_PROVINCE,
SA_ORG_EN_CITY,
SA_ORG_FR_SLUG,
SA_ORG_FR_ACRONYM,
SA_ORG_FR_NAME,
SA_ORG_FR_ZONE,
SA_ORG_FR_SECTOR,
SA_ORG_FR_COUNTRY,
SA_ORG_FR_PROVINCE,
SA_ORG_FR_CITY,
} = process.env
const createSuperAdminOrg = async ({ collections, transaction }) => {
// Generate list of collections names
const collectionStrings = []
for (const property in collections) {
collectionStrings.push(property.toString())
}
// Setup Transaction
const trx = await transaction(collectionStrings)
let org
try {
await trx.step(async () => {
org = await collections.organizations.save({
verified: false,
orgDetails: {
en: {
slug: SA_ORG_EN_SLUG,
acronym: SA_ORG_EN_ACRONYM,
name: SA_ORG_EN_NAME,
zone: SA_ORG_EN_ZONE,
sector: SA_ORG_EN_SECTOR,
country: SA_ORG_EN_COUNTRY,
province: SA_ORG_EN_PROVINCE,
city: SA_ORG_EN_CITY,
},
fr: {
slug: SA_ORG_FR_SLUG,
acronym: SA_ORG_FR_ACRONYM,
name: SA_ORG_FR_NAME,
zone: SA_ORG_FR_ZONE,
sector: SA_ORG_FR_SECTOR,
country: SA_ORG_FR_COUNTRY,
province: SA_ORG_FR_PROVINCE,
city: SA_ORG_FR_CITY,
},
},
})
})
} catch (err) {
await trx.abort()
throw new Error(
`Transaction step error occurred while creating new super admin org: ${err}`,
)
}
try {
await trx.commit()
} catch (err) {
await trx.abort()
throw new Error(
`Transaction commit error occurred while creating new super admin org: ${err}`,
)
}
return org
}
module.exports = {
createSuperAdminOrg,
}