-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
106 lines (88 loc) · 3.03 KB
/
utils.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
var fs = require("fs");
var axios = require("axios");
const translate = require("@vitalets/google-translate-api");
axios.defaults.baseURL = "https://www.mahakim.ma/Ar/Services/SuiviAffaires_new/JFunctions/fn.aspx";
const capitalize = text => {
return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
};
const translateJurisdictionName = async arabicName => {
const res = await translate(arabicName, { to: "fr" }).catch(err => {
console.error(err);
});
return capitalize(res.text);
};
exports.jurisdictionTypes = [
{
code: "CA",
frenchName: "Cours d'appel",
arabicName: "محاكم الإستئناف",
},
{
code: "TPI",
frenchName: "Tribunaux de première instance",
arabicName: "المحاكم الإبتدائية",
},
{
code: "CAC",
frenchName: "Cours d'appel de commerce",
arabicName: "محاكم الإستئناف التجارية",
},
{
code: "TC",
frenchName: "Tribunaux de commerce",
arabicName: "المحاكم التجارية",
},
{
code: "CAA",
frenchName: "Cours administratives d'appel",
arabicName: "محاكم الإستئناف الإدارية",
},
{
code: "TA",
frenchName: "Tribunaux administratifs",
arabicName: "المحاكم الإدارية",
},
{
code: "CC",
frenchName: "Cour de cassation",
arabicName: "محكمة النقض",
},
];
exports.serializeJurisdictionFromMahakimData = async (mahakimJurisdiction, type) => {
const arabicName = mahakimJurisdiction["nomJuridiction"].trim();
const frenchName = await translateJurisdictionName(arabicName);
return {
mahakimId: mahakimJurisdiction["idJuridiction"],
type,
frenchName,
arabicName,
};
};
exports.fetchParentJurisdictions = async jurisdictionTypeCode => {
const res = await axios.post("/getCA", { typeJuridiction: jurisdictionTypeCode });
return res.data["d"];
};
exports.fetchChildJurisdictionsByInstance = async secondJurisdictionInstanceId => {
const res = await axios.post("/getJuridiction1instance", {
IdJuridiction2Instance: secondJurisdictionInstanceId,
});
return res.data["d"];
};
exports.fetchChildJurisdictionsByParent = async parentJurisdictionId => {
const res = await axios.post("/GetListJuridByIdJuridParent", {
IdJuridictionParent: parentJurisdictionId,
});
return res.data["d"];
};
exports.writeJurisdictionsIntoJsonFile = jurisdictionsGroupedByType => {
fs.readFile("jurisdictions-groupedby-type.json", (err, data) => {
if (err) console.error("Error reading the jurisdictions-groupedby-type file");
let jurisdictionsGroupedByTypeList = JSON.parse(data);
jurisdictionsGroupedByTypeList = jurisdictionsGroupedByType;
console.info("Writing to jurisdictions-groupedby-type file ...");
fs.writeFile("jurisdictions-groupedby-type.json", JSON.stringify(jurisdictionsGroupedByTypeList), err => {
if (err) console.error("Error Writing to jurisdictions-groupedby-type");
console.info(`Jurisdictions grouped by type were written into the file successfully`);
});
});
};