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 {