GetCarnetSummaryData response modification done
This commit is contained in:
parent
b41e00959c
commit
1f318d0039
@ -120,7 +120,40 @@ export class HomePageService {
|
||||
throw new BadRequestException(fres[0].ERRORMESG)
|
||||
}
|
||||
|
||||
return fres;
|
||||
// Step 1: Replace spaces in keys
|
||||
const mappedRows = fres.map((obj) => {
|
||||
const newObj = {};
|
||||
for (const key in obj) {
|
||||
const newKey = key.replace(/ /g, '_');
|
||||
newObj[newKey] = obj[key];
|
||||
}
|
||||
return newObj;
|
||||
});
|
||||
|
||||
// Step 2: Group and aggregate
|
||||
const reducedRows = mappedRows.reduce((acc, curr) => {
|
||||
const existing = acc.find(
|
||||
(item) =>
|
||||
item['Service_Provider_Name'] === curr['Service_Provider_Name'] &&
|
||||
item.SPID === curr.SPID
|
||||
);
|
||||
|
||||
if (existing) {
|
||||
existing.CARNETSTATUS.push(curr.CARNETSTATUS);
|
||||
existing.Carnet_Count.push(curr.Carnet_Count);
|
||||
} else {
|
||||
acc.push({
|
||||
Service_Provider_Name: curr.Service_Provider_Name,
|
||||
SPID: curr.SPID,
|
||||
CARNETSTATUS: [curr.CARNETSTATUS],
|
||||
Carnet_Count: [curr.Carnet_Count],
|
||||
});
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
return reducedRows;
|
||||
} catch (error) {
|
||||
handleError(error, HomePageService.name)
|
||||
} finally {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user