From 1f318d0039524daf098b12849218a7f35ee9ba13 Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Sat, 28 Jun 2025 10:04:33 +0530 Subject: [PATCH] GetCarnetSummaryData response modification done --- src/oracle/home-page/home-page.service.ts | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/oracle/home-page/home-page.service.ts b/src/oracle/home-page/home-page.service.ts index b4d962d..bbc201d 100644 --- a/src/oracle/home-page/home-page.service.ts +++ b/src/oracle/home-page/home-page.service.ts @@ -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 {