forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove-super-admin-affiliation.js
More file actions
41 lines (37 loc) · 925 Bytes
/
remove-super-admin-affiliation.js
File metadata and controls
41 lines (37 loc) · 925 Bytes
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
const removeSuperAdminAffiliation = async ({
query,
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)
try {
await trx.step(async () => {
await query`
FOR affiliation IN affiliations
FILTER affiliation.defaultSA == true
REMOVE affiliation IN affiliations
RETURN OLD
`
})
} catch (err) {
throw new Error(
`Transaction step error occurred well removing super admin affiliation: ${err}`,
)
}
try {
await trx.commit()
} catch (err) {
throw new Error(
`Transaction commit error occurred while removing new super admin affiliation: ${err}`,
)
}
}
module.exports = {
removeSuperAdminAffiliation,
}