added cors

This commit is contained in:
Kallesh B S 2025-03-13 11:29:54 +05:30
parent 348845fb6e
commit 2cd381240b
2 changed files with 43 additions and 3 deletions

View File

@ -11,7 +11,7 @@ export class AuthService {
async login(body:AuthLoginDTO) { async login(body:AuthLoginDTO) {
let connection; let connection;
let rows = []; let rows = [];
let crows = []; let crows:any = [];
try { try {
connection = await this.oracleDBService.getConnection() connection = await this.oracleDBService.getConnection()
if (!connection) { if (!connection) {
@ -79,7 +79,42 @@ export class AuthService {
throw new Error('No cursor returned from the stored procedure'); 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) { } catch (err) {
console.error('Error fetching users: ', err); console.error('Error fetching users: ', err);

View File

@ -5,7 +5,12 @@ import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { SwaggerDocumentOptions } from '@nestjs/swagger'; import { SwaggerDocumentOptions } from '@nestjs/swagger';
async function bootstrap() { 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()); app.useGlobalPipes(new ValidationPipe());
const config = new DocumentBuilder() const config = new DocumentBuilder()