-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
62 lines (54 loc) · 2.23 KB
/
index.js
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
const {
fetchParentJurisdictions,
fetchChildJurisdictionsByInstance,
fetchChildJurisdictionsByParent,
serializeJurisdictionFromMahakimData,
writeJurisdictionsIntoJsonFile,
jurisdictionTypes,
} = require("./utils");
(async function () {
try {
var jurisdictions = [];
for (const jurisdictionType of jurisdictionTypes) {
if (jurisdictionType.code === "CC") {
jurisdictionType["jurisdictions"] = [
{
mahakimId: null,
type: "CC",
frenchName: "Cour de cassation",
arabicName: "محكمة النقض",
},
];
continue;
}
console.info(`Fetching jurisdictions of type ${jurisdictionType.code} ...`);
const mahakimJurisdictions = await fetchParentJurisdictions(jurisdictionType.code);
for (const mahakimJurisdiction of mahakimJurisdictions) {
// if it's none appeal court whe need to fetch child insteadof parents jurisdictions
if (["TPI", "TC", "TA"].includes(jurisdictionType.code)) {
let mahakimChildJurisdictions = await fetchChildJurisdictionsByInstance(mahakimJurisdiction["idJuridiction"]);
for (const mahakimChildJurisdiction of mahakimChildJurisdictions) {
jurisdictions.push(
await serializeJurisdictionFromMahakimData(mahakimChildJurisdiction, jurisdictionType.code)
);
}
mahakimChildJurisdictions = await fetchChildJurisdictionsByParent(mahakimJurisdiction["idJuridiction"]);
for (const mahakimChildJurisdiction of mahakimChildJurisdictions) {
if (!jurisdictions.map(jur => jur["mahakimId"]).includes(mahakimChildJurisdiction["idJuridiction"])) {
jurisdictions.push(
await serializeJurisdictionFromMahakimData(mahakimChildJurisdiction, jurisdictionType.code)
);
}
}
} else {
jurisdictions.push(await serializeJurisdictionFromMahakimData(mahakimJurisdiction, jurisdictionType.code));
}
}
jurisdictionType["jurisdictions"] = jurisdictions;
jurisdictions = [];
}
writeJurisdictionsIntoJsonFile(jurisdictionTypes);
} catch (err) {
console.log(err.response.data["Message"] || err);
}
})();