forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove-ownership.js
More file actions
61 lines (57 loc) · 1.77 KB
/
remove-ownership.js
File metadata and controls
61 lines (57 loc) · 1.77 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
const removeOwnership =
({ transaction, collections, query }) =>
async ({ domain, orgAcronymEn }) => {
// Generate list of collections names
const collectionStrings = []
for (const property in collections) {
collectionStrings.push(property.toString())
}
// setup Transaction
const trx = await transaction(collectionStrings)
await trx.step(
() => query`
WITH domains, organizations, ownership
LET domainId = FIRST(
FOR domain IN domains
FILTER domain.domain == ${domain}
RETURN domain._id
)
LET orgId = FIRST(
FOR org IN organizations
FILTER org.orgDetails.en.acronym == ${orgAcronymEn}
RETURN org._id
)
FOR owner IN ownership
FILTER owner._from == orgId
FILTER owner._to == domainId
REMOVE { _key: owner._key } IN ownership
`,
)
// remove dmarcSummaries and dmarcSummaryEdges
await trx.step(() => query`
WITH domains, dmarcSummaries, domainsToDmarcSummaries
LET domainId = FIRST(
FOR domain IN domains
FILTER domain.domain == ${domain}
RETURN domain._id
)
LET dmarcSummaryEdges = (
FOR v, e IN 1..1 OUTBOUND domainId domainsToDmarcSummaries
RETURN { edgeKey: e._key, dmarcSummaryId: e._to }
)
LET removeDmarcSummaryEdges = (
FOR dmarcSummaryEdge IN dmarcSummaryEdges
REMOVE dmarcSummaryEdge.edgeKey IN domainsToDmarcSummaries
)
LET removeDmarcSummaries = (
FOR dmarcSummaryEdge IN dmarcSummaryEdges
LET key = PARSE_IDENTIFIER(dmarcSummaryEdge.dmarcSummaryId).key
REMOVE key IN dmarcSummaries
)
RETURN true
`)
await trx.commit()
}
module.exports = {
removeOwnership,
}