modified for res code

This commit is contained in:
Kallesh B S 2025-05-06 13:04:00 +05:30
parent ecb9974f03
commit b6e13398bd
6 changed files with 739 additions and 495 deletions

View File

@ -8,12 +8,12 @@ export class BadRequestException extends HttpException {
) {
super(
{
statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
statusCode: HttpStatus.BAD_REQUEST ,
message,
// errorCode,
// data,
},
HttpStatus.INTERNAL_SERVER_ERROR,
HttpStatus.BAD_REQUEST,
);
}
}

View File

@ -1,12 +1,12 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {
BadRequestException,
ValidationError,
ValidationPipe,
} from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { SwaggerDocumentOptions } from '@nestjs/swagger';
import { BadRequestException } from './exceptions/badRequest.exception';
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
@ -56,10 +56,7 @@ async function bootstrap() {
})
.filter(Boolean);
throw new BadRequestException({
message: 'Validation failed',
errors: newResult,
});
throw new BadRequestException(newResult[0].message);
};
app.useGlobalPipes(
@ -77,11 +74,11 @@ async function bootstrap() {
.setTitle('API')
.setDescription('API description')
.setVersion('1.0')
.addServer('http://localhost:3000', 'Development Server 1')
.addServer(
'https://dev.alphaomegainfosys.com/test-api',
'Development Server 2',
)
.addServer('http://localhost:3000', 'Development Server 1')
.build();
const options: SwaggerDocumentOptions = {

View File

@ -17,6 +17,7 @@ import {
UpdateCsFeeDTO,
UpdateEfFeeDTO,
UpdateFeeCommBodyDTO,
UpdateFeeCommDTO,
} from './manage-fee.dto';
@Controller('oracle')
@ -145,7 +146,7 @@ export class ManageFeeController {
@ApiTags('Manage Fee - Oracle')
@Patch('/UpdateFeeComm')
UpdateFeeComm(@Body() body: UpdateFeeCommBodyDTO) {
UpdateFeeComm(@Body() body: UpdateFeeCommDTO) {
return this.manageFeeService.UPDATEFEECOMM(body);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -40,16 +40,16 @@ export class InsertNewServiceProviderDTO {
@IsDefined({ message: 'Property p_state is required' })
p_state: string;
@ApiProperty({ required: true })
@IsString({ message: 'Property p_zip must be a string' })
@IsDefined({ message: 'Property p_zip is required' })
p_zip: string;
@ApiProperty({ required: true })
@IsString({ message: 'Property p_country must be a string' })
@IsDefined({ message: 'Property p_country is required' })
p_country: string;
@ApiProperty({ required: true })
@IsString({ message: 'Property p_zip must be a string' })
@IsDefined({ message: 'Property p_zip is required' })
p_zip: string;
@ApiProperty({ required: true })
@IsString({ message: 'Property p_issuingregion must be a string' })
@IsDefined({ message: 'Property p_issuingregion is required' })
@ -127,11 +127,6 @@ export class UpdateServiceProviderDTO {
@IsDefined({ message: 'Property p_state is required' })
p_state: string;
@ApiProperty({ required: true })
@IsString({ message: 'Property p_zip must be a string' })
@IsDefined({ message: 'Property p_zip is required' })
p_zip: string;
@ApiProperty({ required: true })
@IsString({ message: 'Property p_country must be a string' })
@IsDefined({ message: 'Property p_country is required' })
@ -162,6 +157,11 @@ export class UpdateServiceProviderDTO {
@IsDefined({ message: 'Property p_cargosurety is required' })
p_cargosurety: string;
@ApiProperty({ required: true })
@IsString({ message: 'Property p_zip must be a string' })
@IsDefined({ message: 'Property p_zip is required' })
p_zip: string;
@ApiProperty({ required: true })
@IsString({ message: 'Property p_user_id must be a string' })
@IsDefined({ message: 'Property p_user_id is required' })
@ -176,6 +176,7 @@ export class UpdateServiceProviderDTO {
@IsString({ message: 'Property P_FILEIDS must be a string' })
@IsOptional()
P_FILEIDS?: string;
}
export class getSelectedServiceproviderDTO {

View File

@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { OracleDBService } from 'src/db/db.service';
import * as oracledb from 'oracledb';
import {
@ -6,40 +6,45 @@ import {
InsertNewServiceProviderDTO,
UpdateServiceProviderDTO,
} from './sp.dto';
import { BadRequestException } from 'src/exceptions/badRequest.exception';
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
@Injectable()
export class SpService {
constructor(private readonly oracleDBService: OracleDBService) {}
private readonly logger = new Logger(SpService.name);
constructor(private readonly oracleDBService: OracleDBService) { }
async insertNewServiceProvider(body: InsertNewServiceProviderDTO) {
let connection;
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
this.logger.error(`Database connection failed`);
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.InsertNewSP(
:p_name,
:p_lookupcode,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_issuingregion,
:p_replacementregion,
:p_bondsurety,
:p_cargopolicyno,
:p_cargosurety,
:p_user_id,
:P_NOTES,
:P_FILEIDS,
:p_cursor);
END;`,
USCIB_Managed_Pkg.InsertNewSP(
:p_name,
:p_lookupcode,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_issuingregion,
:p_replacementregion,
:p_bondsurety,
:p_cargopolicyno,
:p_cargosurety,
:p_user_id,
:P_NOTES,
:P_FILEIDS,
:p_cursor);
END;`,
{
p_name: {
val: body.p_name,
@ -119,122 +124,165 @@ export class SpService {
const fres = await result.outBinds.p_cursor.getRows();
return fres;
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
if (fres[0].ERRORMESG) {
console.log(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
}
finally {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('insertNewServiceProvider failed', error.stack || error);
throw new InternalServerException();
} finally {
if (connection) {
try {
await connection.close();
} catch (closeErr) {
console.error('Failed to close connection:', closeErr);
this.logger.error('Failed to close DB connection', closeErr);
}
}
}
}
async updateServiceProvider(body: UpdateServiceProviderDTO) {
const newBody = {
p_spid: null,
p_name: null,
p_lookupcode: null,
p_address1: null,
p_address2: null,
p_city: null,
p_state: null,
p_zip: null,
p_country: null,
p_issuingregion: null,
p_replacementregion: null,
p_bondsurety: null,
p_cargopolicyno: null,
p_cargosurety: null,
p_user_id: null
};
const reqBody = JSON.parse(JSON.stringify(body));
function setEmptyStringsToNull(obj) {
Object.keys(obj).forEach((key) => {
if (typeof obj[key] === 'object' && obj[key] !== null) {
setEmptyStringsToNull(obj[key]);
} else if (obj[key] === '') {
obj[key] = null;
}
});
}
setEmptyStringsToNull(reqBody);
const finalBody: UpdateServiceProviderDTO = { ...newBody, ...reqBody };
let connection;
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
this.logger.error(`Database connection failed`);
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.UpdateSP(
:p_spid,
:p_name,
:p_lookupcode,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_issuingregion,
:p_replacementregion,
:p_bondsurety,
:p_cargopolicyno,
:p_cargosurety,
:p_user_id,
:P_NOTES,
:P_FILEIDS,
:p_cursor);
END;`,
USCIB_Managed_Pkg.UpdateSP(
:p_spid,
:p_name,
:p_lookupcode,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_issuingregion,
:p_replacementregion,
:p_bondsurety,
:p_cargopolicyno,
:p_cargosurety,
:p_user_id,
:P_NOTES,
:P_FILEIDS,
:p_cursor);
END;`,
{
p_spid: {
val: body.p_spid,
val: finalBody.p_spid,
type: oracledb.DB_TYPE_NUMBER,
},
p_name: {
val: body.p_name,
val: finalBody.p_name,
type: oracledb.DB_TYPE_VARCHAR,
},
p_lookupcode: {
val: body.p_lookupcode,
val: finalBody.p_lookupcode,
type: oracledb.DB_TYPE_VARCHAR,
},
p_address1: {
val: body.p_address1,
val: finalBody.p_address1,
type: oracledb.DB_TYPE_VARCHAR,
},
p_address2: {
val: body.p_address2,
val: finalBody.p_address2,
type: oracledb.DB_TYPE_VARCHAR,
},
p_city: {
val: body.p_city,
val: finalBody.p_city,
type: oracledb.DB_TYPE_VARCHAR,
},
p_state: {
val: body.p_state,
val: finalBody.p_state,
type: oracledb.DB_TYPE_VARCHAR,
},
p_zip: {
val: body.p_zip,
val: finalBody.p_zip,
type: oracledb.DB_TYPE_VARCHAR,
},
p_country: {
val: body.p_country,
val: finalBody.p_country,
type: oracledb.DB_TYPE_VARCHAR,
},
p_issuingregion: {
val: body.p_issuingregion,
val: finalBody.p_issuingregion,
type: oracledb.DB_TYPE_VARCHAR,
},
p_replacementregion: {
val: body.p_replacementregion,
val: finalBody.p_replacementregion,
type: oracledb.DB_TYPE_VARCHAR,
},
p_bondsurety: {
val: body.p_bondsurety,
val: finalBody.p_bondsurety,
type: oracledb.DB_TYPE_VARCHAR,
},
p_cargopolicyno: {
val: body.p_cargopolicyno,
val: finalBody.p_cargopolicyno,
type: oracledb.DB_TYPE_VARCHAR,
},
p_cargosurety: {
val: body.p_cargosurety,
val: finalBody.p_cargosurety,
type: oracledb.DB_TYPE_VARCHAR,
},
p_user_id: {
val: body.p_user_id,
val: finalBody.p_user_id,
type: oracledb.DB_TYPE_VARCHAR,
},
P_NOTES: {
val: body.P_NOTES,
val: finalBody.P_NOTES,
type: oracledb.DB_TYPE_VARCHAR,
},
P_FILEIDS: {
val: body.P_FILEIDS,
val: finalBody.P_FILEIDS,
type: oracledb.DB_TYPE_VARCHAR,
},
p_cursor: {
@ -251,20 +299,27 @@ export class SpService {
const fres = await result.outBinds.p_cursor.getRows();
return fres;
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
if (fres[0].ERRORMESG) {
console.log(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
}
finally {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('updateServiceProvider failed', error.stack || error);
throw new InternalServerException();
} finally {
if (connection) {
try {
await connection.close();
} catch (closeErr) {
console.error('Failed to close connection:', closeErr);
this.logger.error('Failed to close DB connection', closeErr);
}
}
}
@ -272,17 +327,18 @@ export class SpService {
async getAllServiceproviders() {
let connection;
let rows = [];
let rows: any = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
this.logger.error(`Database connection failed`);
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.GetAllSPs(:p_cursor);
END;`,
USCIB_Managed_Pkg.GetAllSPs(:p_cursor);
END;`,
{
p_cursor: {
type: oracledb.CURSOR,
@ -305,23 +361,30 @@ export class SpService {
await cursor.close();
if (rows.length > 0 && rows[0].ERRORMESG) {
this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`);
throw new BadRequestException(rows[0].ERRORMESG);
}
return rows;
} else {
throw new Error('No cursor returned from the stored procedure');
throw new BadRequestException();
}
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
throw error;
}
}
finally {
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('getAllServiceproviders failed', error.stack || error);
throw new InternalServerException();
} finally {
if (connection) {
try {
await connection.close();
} catch (closeErr) {
console.error('Failed to close connection:', closeErr);
this.logger.error('Failed to close DB connection', closeErr);
}
}
}
@ -329,17 +392,18 @@ export class SpService {
async getServiceproviderByID(body: getSelectedServiceproviderDTO) {
let connection;
let rows = [];
let rows: any = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
this.logger.error(`Database connection failed`);
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.GetSPbySPID(:p_spid,:p_cursor);
END;`,
USCIB_Managed_Pkg.GetSPbySPID(:p_spid,:p_cursor);
END;`,
{
p_spid: {
val: body.p_spid,
@ -366,23 +430,30 @@ export class SpService {
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
throw new BadRequestException();
}
if (rows.length > 0 && rows[0].ERRORMESG) {
this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`);
throw new BadRequestException(rows[0].ERRORMESG);
}
return rows;
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
throw error;
}
}
finally {
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('getServiceproviderByID failed', error.stack || error);
throw new InternalServerException();
} finally {
if (connection) {
try {
await connection.close();
} catch (closeErr) {
console.error('Failed to close connection:', closeErr);
this.logger.error('Failed to close DB connection', closeErr);
}
}
}