-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformer.txt
50 lines (50 loc) · 1.9 KB
/
transformer.txt
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
private fetchPriceList(): void {
this.apiSvc.getPriceList().subscribe(
data => {
data.forEach(element => {
if (!isNaN(Number(element.Size))) {
element.length = Number(element.Size[0]);
element.width = Number(element.Size[1]);
element.size = `${element.length}x${element.width}`,
element.isSizingApplicable = true;
} else {
element.isSizingApplicable = false;
}
element.rate = Number(element.Rate.split(',').map(u => u.trim()).join(''));
element.brand = element.Brand.trim();
element.grade = element.Grade.trim();
element.particulars = element.Particulars.trim();
delete element.Brand;
delete element.Grade;
delete element.Rate;
delete element.Particulars;
delete element.Size;
});
console.log(data);
const allBrands = [...new Set(data.map(u => u.brand))];
const formattedJson = {};
allBrands.forEach((brand: string) => {
const brandItems = data.filter(u => u.brand === brand);
const brandGrades = [...new Set(brandItems.map(u => u.grade))] as string[];
const gradeData = {};
brandGrades.forEach((grade) => {
const gradedItems = brandItems.filter(u => u.grade === grade);
const unitGradeData = [];
gradedItems.forEach(element => {
unitGradeData.push({
rate: element.rate,
isSizingApplicable: element.isSizingApplicable,
particulars: element.particulars,
length: element.length,
width: element.width,
size: element.size
});
});
gradeData[grade] = unitGradeData;
});
formattedJson[brand] = gradeData;
});
console.log(formattedJson);
}
);
}