-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmappingPartTypeScript.js
More file actions
66 lines (58 loc) · 1.75 KB
/
mappingPartTypeScript.js
File metadata and controls
66 lines (58 loc) · 1.75 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
exports.step = function (input) {
const parser = require("csv-parse/sync");
const partTypesCsv = fs.readFileSync("./input/sapToMxPartTypes.csv", {
encoding: "utf8",
flag: "r",
});
const types = parser.parse(partTypesCsv, {
columns: true,
skip_empty_lines: true,
});
const PartTypesKeyedBySapCode = {};
const PartTypesKeyedByMXCode = {};
for (const {
ProductType,
SupportsPlantStock,
SupportsPurchasing,
SupportsValuation,
DefaultValuationClass,
MXPartType,
} of types) {
PartTypesKeyedBySapCode[ProductType] = {
SupportsPlantStock: "true" === SupportsPlantStock,
SupportsPurchasing: "true" === SupportsPurchasing,
SupportsValuation: "true" === SupportsValuation,
DefaultValuationClass,
MXPartType,
};
PartTypesKeyedByMXCode[MXPartType] = {
ProductType,
SupportsPlantStock: "true" === SupportsPlantStock,
SupportsPurchasing: "true" === SupportsPurchasing,
SupportsValuation: "true" === SupportsValuation,
DefaultValuationClass,
};
}
const MxPartTypes = Object.keys(PartTypesKeyedByMXCode);
writeFile("PartTypesKeyedBySapCode.json", PartTypesKeyedBySapCode);
writeFile("PartTypesKeyedByMXCode.json", PartTypesKeyedByMXCode);
writeFile("MxPartTypes.json", MxPartTypes);
const restQueryPartTypes = {
PartTypesKeyedBySapCode,
PartTypesKeyedByMXCode,
MxPartTypes,
};
writeFile("RestQueryPartTypes.json", restQueryPartTypes);
return {
PartTypesKeyedBySapCode,
PartTypesKeyedByMXCode,
};
};
function writeFile(fileName, data) {
fs.writeFile("output/" + fileName, JSON.stringify(data), (err) => {
if (err) {
console.error(err);
}
console.log(`${fileName} has been written successfully`);
});
}