diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index d6fe172..9075b2b 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -11,7 +11,7 @@ export class AuthService { async login(body:AuthLoginDTO) { let connection; let rows = []; - let crows = []; + let crows:any = []; try { connection = await this.oracleDBService.getConnection() if (!connection) { @@ -79,7 +79,42 @@ export class AuthService { throw new Error('No cursor returned from the stored procedure'); } - return {rows,crows}; + crows = crows.map(obj => { + // Create a new object to hold the modified keys + let newObj = {}; + + // Iterate over the keys of the current object + for (let key in obj) { + // Replace spaces with underscores in the key + let newKey = key.replace(/ /g, "_"); + newObj[newKey] = obj[key]; + } + + return newObj; + }); + + crows = crows.reduce((acc, curr) => { + // Find if the current item already exists in the accumulator + let existing = acc.find(item => item["Service_Provider_Name"] === curr["Service_Provider_Name"] && item.SPID === curr.SPID); + + if (existing) { + // If it exists, push the current "cs" and "c c" values into the arrays + existing.CARNETSTATUS.push(curr.CARNETSTATUS); + existing["Carnet_Count"].push(curr["Carnet_Count"]); + } else { + // If it doesn't exist, create a new entry + acc.push({ + "Service_Provider_Name": curr["Service_Provider_Name"], + SPID: curr.SPID, + CARNETSTATUS: [curr.CARNETSTATUS], + "Carnet_Count": [curr["Carnet_Count"]] + }); + } + + return acc; + }, []); + + return {rows,chartResult:crows}; } catch (err) { console.error('Error fetching users: ', err); diff --git a/src/main.ts b/src/main.ts index 42c591d..d0a5f9b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,7 +5,12 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { SwaggerDocumentOptions } from '@nestjs/swagger'; async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule, {cors:{ + "origin": "*", + "methods": "GET,HEAD,PUT,PATCH,POST,DELETE", + "preflightContinue": false, + "optionsSuccessStatus": 204 + }}); app.useGlobalPipes(new ValidationPipe()); const config = new DocumentBuilder()