modified res code except holder clients homepage

This commit is contained in:
Kallesh B S 2025-05-07 16:20:29 +05:30
parent d0c175800e
commit 3f5a6d45ca
10 changed files with 462 additions and 435 deletions

View File

@ -10,6 +10,7 @@ import { BadRequestException } from './exceptions/badRequest.exception';
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger:['error','warn'],
cors: {
// origin: 'https://dev.alphaomegainfosys.com/',
origin: '*',

View File

@ -85,9 +85,11 @@ export class ManageFeeService {
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('GETBASICFEERATES failed', error.stack || error);
@ -158,9 +160,11 @@ export class ManageFeeService {
return rows;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('GETBONDRATES failed', error.stack || error);
@ -231,9 +235,11 @@ export class ManageFeeService {
return rows;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('GETCARGORATES failed', error.stack || error);
@ -306,9 +312,11 @@ export class ManageFeeService {
return rows;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('GETCFFEERATES failed', error.stack || error);
@ -374,9 +382,11 @@ export class ManageFeeService {
return rows;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('GETCSFEERATES failed', error.stack || error);
@ -442,9 +452,11 @@ export class ManageFeeService {
return rows;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('GETEFFEERATES failed', error.stack || error);
@ -510,12 +522,14 @@ export class ManageFeeService {
return rows;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('GETFEECOMM failed', error.stack || error);
this.logger.error('GETFEECOMM failed\n', error.stack || error);
throw new InternalServerException();
} finally {
if (connection) {
@ -597,11 +611,9 @@ export class ManageFeeService {
return { statusCode: 201, message: "Created Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('CREATEBASICFEE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -691,11 +703,9 @@ export class ManageFeeService {
return { statusCode: 201, message: "Created Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('CREATEBONDRATE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -780,11 +790,9 @@ export class ManageFeeService {
return { statusCode: 201, message: "Created Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('CREATECARGORATE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -874,11 +882,9 @@ export class ManageFeeService {
return { statusCode: 201, message: "Created Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('CREATECFFEE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -958,11 +964,9 @@ export class ManageFeeService {
return { statusCode: 201, message: "Created Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('CREATECSFEE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -1058,11 +1062,9 @@ export class ManageFeeService {
return { statusCode: 201, message: "Created Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('CREATEEFFEE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -1130,18 +1132,16 @@ export class ManageFeeService {
const fres = await result.outBinds.P_CURSOR.getRows();
if (fres[0].ERRORMESG) {
console.log(fres[0].ERRORMESG);
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
return { statusCode: 201, message: "Created Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('CREATEFEECOMM failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -1213,11 +1213,9 @@ export class ManageFeeService {
return { statusCode: 200, message: "Updated Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('UPDATEBASICFEE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -1287,11 +1285,9 @@ export class ManageFeeService {
return { statusCode: 200, message: "Updated Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('UPDATEBONDRATE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -1361,11 +1357,9 @@ export class ManageFeeService {
return { statusCode: 200, message: "Updated Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('UPDATECARGORATE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -1435,11 +1429,9 @@ export class ManageFeeService {
return { statusCode: 200, message: "Updated Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('UPDATECFFEE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -1509,11 +1501,9 @@ export class ManageFeeService {
return { statusCode: 200, message: "Updated Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('UPDATECSFEE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -1583,11 +1573,9 @@ export class ManageFeeService {
return { statusCode: 200, message: "Updated Successfully" };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('UPDATEEFFEE failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -1663,11 +1651,9 @@ export class ManageFeeService {
}
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('UPDATEFEECOMM failed', error.stack || error);
throw new InternalServerException();
} finally {

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 {
CreateHoldersDTO,
@ -11,9 +11,13 @@ import {
} from './manage-holders.dto';
import * as oracledb from 'oracledb';
import { Connection, Result } from 'oracledb';
import { BadRequestException } from 'src/exceptions/badRequest.exception';
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
@Injectable()
export class ManageHoldersService {
private readonly logger = new Logger(ManageHoldersService.name);
constructor(private readonly oracleDBService: OracleDBService) { }
CreateHolders = async (body: CreateHoldersDTO) => {
@ -59,7 +63,7 @@ export class ManageHoldersService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
// let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CONTACT%'`);
@ -126,28 +130,28 @@ export class ManageHoldersService {
const result: Result<any> = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.CreateHolderData(
:p_spid,
:p_clientlocationid,
:p_holderno,
:p_holdertype,
:p_uscibmemberflag,
:p_govagencyflag,
:p_holdername,
:p_namequalifier,
:p_addlname,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_userid,
:p_contactstable,
:p_holdercursor,
:p_holdercontactcursor
);
END;`,
MANAGEHOLDER_PKG.CreateHolderData(
:p_spid,
:p_clientlocationid,
:p_holderno,
:p_holdertype,
:p_uscibmemberflag,
:p_govagencyflag,
:p_holdername,
:p_namequalifier,
:p_addlname,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_userid,
:p_contactstable,
:p_holdercursor,
:p_holdercontactcursor
);
END;`,
{
p_spid: {
val: finalBody.p_spid ? finalBody.p_spid : null,
@ -251,7 +255,7 @@ export class ManageHoldersService {
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
throw new BadRequestException();
}
if (result.outBinds && result.outBinds.p_holdercontactcursor) {
@ -266,7 +270,7 @@ export class ManageHoldersService {
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
throw new BadRequestException();
}
return {
@ -275,19 +279,19 @@ export class ManageHoldersService {
};
// return fres
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
}
finally {
this.logger.error('CreateHolders 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);
}
}
}
@ -461,19 +465,19 @@ export class ManageHoldersService {
return { P_cursor: P_cursor_rows };
// return fres
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
}
finally {
this.logger.error('CREATEFEECOMM 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);
}
}
}
@ -528,19 +532,19 @@ export class ManageHoldersService {
}
return { p_cursor: p_cursor_rows };
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
}
finally {
this.logger.error('CREATEFEECOMM 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);
}
}
}
@ -678,19 +682,19 @@ export class ManageHoldersService {
return { P_cursor: P_cursor_rows };
// return fres
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
}
finally {
this.logger.error('CREATEFEECOMM 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);
}
}
}
@ -745,19 +749,19 @@ export class ManageHoldersService {
}
return { p_cursor: p_cursor_rows };
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
}
finally {
this.logger.error('CREATEFEECOMM 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);
}
}
}
@ -817,19 +821,19 @@ export class ManageHoldersService {
}
return { p_cursor: p_cursor_rows };
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
}
finally {
this.logger.error('CREATEFEECOMM 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);
}
}
}
@ -889,19 +893,19 @@ export class ManageHoldersService {
}
return { p_cursor: p_cursor_rows };
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
}
finally {
this.logger.error('CREATEFEECOMM 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);
}
}
}
@ -961,19 +965,19 @@ export class ManageHoldersService {
}
return { p_cursor: p_cursor_rows };
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
}
finally {
this.logger.error('CREATEFEECOMM 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);
}
}
}
@ -1033,19 +1037,19 @@ export class ManageHoldersService {
}
return { p_cursor: p_cursor_rows };
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
}
finally {
this.logger.error('CREATEFEECOMM 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);
}
}
}

View File

@ -50,13 +50,13 @@ export class ParamTableController {
}
@ApiTags('Param Table - Oracle')
@Put('/InActivateParamRecord')
@Patch('/InActivateParamRecord')
inActivateParamRecord(@Body() body: ActivateOrInactivateParamRecordDTO) {
return this.paramTableService.INACTIVATEPARAMRECORD(body);
}
@ApiTags('Param Table - Oracle')
@Put('/ReActivateParamRecord')
@Patch('/ReActivateParamRecord')
reActivateParamRecord(@Body() body: ActivateOrInactivateParamRecordDTO) {
return this.paramTableService.REACTIVATEPARAMRECORD(body);
}

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 {
@ -8,9 +8,13 @@ import {
getParamValuesDTO,
UpdateParamRecordDTO,
} from './param-table.dto';
import { BadRequestException } from 'src/exceptions/badRequest.exception';
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
@Injectable()
export class ParamTableService {
private readonly logger = new Logger(ParamTableService.name);
constructor(private readonly oracleDBService: OracleDBService) { }
async GETPARAMVALUES(body: getParamValuesDTO) {
@ -24,7 +28,7 @@ export class ParamTableService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
@ -61,23 +65,27 @@ export class ParamTableService {
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
throw new BadRequestException();
}
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) {
this.logger.warn(error.message);
throw error;
}
}
finally {
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('GETPARAMVALUES 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);
}
}
}
@ -88,13 +96,13 @@ export class ParamTableService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.CREATETABLERECORD(:P_USERID,:P_TABLEFULLDESC,:p_cursor);
END;`,
MANAGEPARAMTABLE_PKG.CREATETABLERECORD(:P_USERID,:P_TABLEFULLDESC,:p_cursor);
END;`,
{
P_TABLEFULLDESC: {
val: body.P_TABLEFULLDESC,
@ -118,20 +126,25 @@ export class ParamTableService {
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) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
}
finally {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
this.logger.error('CREATETABLERECORD 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);
}
}
}
@ -142,25 +155,25 @@ export class ParamTableService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.CREATEPARAMRECORD(
:P_SPID,
:P_PARAMTYPE,
:P_PARAMDESC,
:P_PARAMVALUE,
:P_ADDLPARAMVALUE1,
:P_ADDLPARAMVALUE2,
:P_ADDLPARAMVALUE3,
:P_ADDLPARAMVALUE4,
:P_ADDLPARAMVALUE5,
:P_SORTSEQ,
:P_USERID,
:p_cursor);
END;`,
MANAGEPARAMTABLE_PKG.CREATEPARAMRECORD(
:P_SPID,
:P_PARAMTYPE,
:P_PARAMDESC,
:P_PARAMVALUE,
:P_ADDLPARAMVALUE1,
:P_ADDLPARAMVALUE2,
:P_ADDLPARAMVALUE3,
:P_ADDLPARAMVALUE4,
:P_ADDLPARAMVALUE5,
:P_SORTSEQ,
:P_USERID,
:p_cursor);
END;`,
{
P_SPID: {
val: body.P_SPID,
@ -220,20 +233,27 @@ export class ParamTableService {
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) {
this.logger.warn(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('CREATEPARAMRECORD 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);
}
}
}
@ -244,24 +264,24 @@ export class ParamTableService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.UPDATEPARAMRECORD(
:P_SPID,
:P_PARAMID,
:P_PARAMDESC,
:P_ADDLPARAMVALUE1,
:P_ADDLPARAMVALUE2,
:P_ADDLPARAMVALUE3,
:P_ADDLPARAMVALUE4,
:P_ADDLPARAMVALUE5,
:P_SORTSEQ,
:P_USERID,
:p_cursor);
END;`,
MANAGEPARAMTABLE_PKG.UPDATEPARAMRECORD(
:P_SPID,
:P_PARAMID,
:P_PARAMDESC,
:P_ADDLPARAMVALUE1,
:P_ADDLPARAMVALUE2,
:P_ADDLPARAMVALUE3,
:P_ADDLPARAMVALUE4,
:P_ADDLPARAMVALUE5,
:P_SORTSEQ,
:P_USERID,
:p_cursor);
END;`,
{
P_SPID: {
val: body.P_SPID,
@ -317,20 +337,25 @@ export class ParamTableService {
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) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
}
finally {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
this.logger.error('UPDATEPARAMRECORD 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);
}
}
}
@ -341,15 +366,15 @@ export class ParamTableService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.INACTIVATEPARAMRECORD(
:P_PARAMID,
:P_USERID);
END;`,
MANAGEPARAMTABLE_PKG.INACTIVATEPARAMRECORD(
:P_PARAMID,
:P_USERID);
END;`,
{
P_PARAMID: {
val: body.P_PARAMID,
@ -363,20 +388,16 @@ export class ParamTableService {
);
await connection.commit();
return 'SP Executed Successfully';
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
}
}
finally {
return { statusCode: 200, message: 'Inactivated Successfully' };
} catch (error) {
this.logger.error('INACTIVATEPARAMRECORD 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);
}
}
}
@ -387,15 +408,15 @@ export class ParamTableService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
MANAGEPARAMTABLE_PKG.REACTIVATEPARAMRECORD(
:P_PARAMID,
:P_USERID);
END;`,
MANAGEPARAMTABLE_PKG.REACTIVATEPARAMRECORD(
:P_PARAMID,
:P_USERID);
END;`,
{
P_PARAMID: {
val: body.P_PARAMID,
@ -409,20 +430,16 @@ export class ParamTableService {
);
await connection.commit();
return 'SP Executed Successfully';
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
}
}
finally {
return { statusCode: 200, message: 'Reactivated Successfully' };
} catch (error) {
this.logger.error('REACTIVATEPARAMRECORD 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);
}
}
}

View File

@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import * as oracledb from 'oracledb';
import { OracleDBService } from 'src/db/db.service';
import {
@ -6,8 +6,13 @@ import {
GetCarnetSequenceDTO,
} from './carnet-sequence.dto';
import { BadRequestException } from 'src/exceptions/badRequest.exception';
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
@Injectable()
export class CarnetSequenceService {
private readonly logger = new Logger(CarnetSequenceService.name);
constructor(private readonly oracleDBService: OracleDBService) {}
async createCarnetSequence(body: CreateCarnetSequenceDTO) {
@ -15,19 +20,19 @@ export class CarnetSequenceService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.CreateCarnetSequence(
:p_spid,
:p_regionid,
:p_startnumber,
:p_endnumber,
:p_carnettype,
:p_cursor);
END;`,
USCIB_Managed_Pkg.CreateCarnetSequence(
:p_spid,
:p_regionid,
:p_startnumber,
:p_endnumber,
:p_carnettype,
:p_cursor);
END;`,
{
p_spid: {
val: body.p_spid,
@ -65,20 +70,25 @@ export class CarnetSequenceService {
await result.outBinds.p_cursor.close();
return fres;
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
if (fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
}
finally {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
this.logger.error('createCarnetSequence 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);
}
}
}
@ -91,13 +101,13 @@ export class CarnetSequenceService {
// Connect to the Oracle database using oracledb
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.GetCarnetSequence(:p_spid,:p_cursor);
END;`,
USCIB_Managed_Pkg.GetCarnetSequence(:p_spid,:p_cursor);
END;`,
{
p_spid: {
val: body.p_spid,
@ -118,29 +128,33 @@ export class CarnetSequenceService {
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
rowsBatch = await cursor.getRows(100);
rows = rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
throw new BadRequestException();
}
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) {
this.logger.warn(error.message);
throw error;
}
}
finally {
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('getCarnetSequence 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);
}
}
}

View File

@ -1,24 +1,28 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { OracleDBService } from 'src/db/db.service';
import * as oracledb from 'oracledb';
import { InsertRegionsDto, UpdateRegionDto } from './region.dto';
import { BadRequestException } from 'src/exceptions/badRequest.exception';
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
@Injectable()
export class RegionService {
constructor(private readonly oracleDBService: OracleDBService) {}
private readonly logger = new Logger(RegionService.name);
constructor(private readonly oracleDBService: OracleDBService) { }
async insertRegions(body: InsertRegionsDto) {
let connection;
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.InsertNewRegion(:p_region,:p_name,:p_cursor);
END;`,
USCIB_Managed_Pkg.InsertNewRegion(:p_region,:p_name,:p_cursor);
END;`,
{
p_region: {
val: body.p_region,
@ -42,20 +46,25 @@ export class RegionService {
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) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
}
finally {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
this.logger.error('insertRegions 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);
}
}
}
@ -66,13 +75,13 @@ export class RegionService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.UpdateRegion(:p_regionID,:p_name,:p_cursor);
END;`,
USCIB_Managed_Pkg.UpdateRegion(:p_regionID,:p_name,:p_cursor);
END;`,
{
p_regionID: {
val: body.p_regionID,
@ -96,20 +105,25 @@ export class RegionService {
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) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
}
finally {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
this.logger.error('updateRegions 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);
}
}
}
@ -119,16 +133,16 @@ export class RegionService {
let connection;
let rows = [];
try {
try {
connection = await this.oracleDBService.getConnection();
} catch (err) {
console.log('DB ERROR: ', err);
return { error: 'Error while connecting to DB' };
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new InternalServerException()
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.GetRegions(:p_cursor);
END;`,
USCIB_Managed_Pkg.GetRegions(:p_cursor);
END;`,
{
p_cursor: {
type: oracledb.CURSOR,
@ -151,23 +165,27 @@ export class RegionService {
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
throw new BadRequestException();
}
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) {
this.logger.warn(error.message);
throw error;
}
}
finally {
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('GETBASICFEERATES 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);
}
}
}

View File

@ -1,5 +1,5 @@
import { SpContactsService } from './sp-contacts.service';
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
import { Body, Controller, Get, Patch, Post, Put, Query } from '@nestjs/common';
import {
getSPAllContactsDTO,
getSPDefaultcontactDTO,
@ -21,7 +21,7 @@ export class SpContactsController {
}
@ApiTags('SPContacts - Oracle')
@Post('/SetSPDefaultContact')
@Patch('/SetSPDefaultContact')
setSPDefaultcontact(@Query() body: setSPDefaultcontactDTO) {
return this.spContactsService.setSPDefaultcontact(body);
}
@ -33,7 +33,7 @@ export class SpContactsController {
}
@ApiTags('SPContacts - Oracle')
@Post('/InactivateSPContact')
@Patch('/InactivateSPContact')
inactivateSPContact(@Query() body: inactivateSPContactDTO) {
return this.spContactsService.inactivateSPContact(body);
}

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 {
@ -9,9 +9,13 @@ import {
setSPDefaultcontactDTO,
UpdateSPContactsDTO,
} from './sp-contacts.dto';
import { BadRequestException } from 'src/exceptions/badRequest.exception';
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
@Injectable()
export class SpContactsService {
private readonly logger = new Logger(SpContactsService.name);
constructor(private readonly oracleDBService: OracleDBService) { }
async insertSPContacts(body: InsertSPContactsDTO) {
@ -19,25 +23,25 @@ export class SpContactsService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.InsertSPContacts(
:p_spid,
:p_defcontactflag,
:p_firstname,
:p_lastname,
:P_MIDDLEINITIAL,
:p_title,
:p_phoneno,
:p_mobileno,
:p_faxno,
:p_emailaddress,
:p_user_id,
:p_cursor);
END;`,
USCIB_Managed_Pkg.InsertSPContacts(
:p_spid,
:p_defcontactflag,
:p_firstname,
:p_lastname,
:P_MIDDLEINITIAL,
:p_title,
:p_phoneno,
:p_mobileno,
:p_faxno,
:p_emailaddress,
:p_user_id,
:p_cursor);
END;`,
{
p_spid: {
val: body.p_spid,
@ -97,20 +101,24 @@ export class SpContactsService {
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) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
}
finally {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
throw error;
}
this.logger.error('insertSPContacts 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);
}
}
}
@ -121,13 +129,13 @@ export class SpContactsService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.SetDefaultContact(:p_spcontactid);
END;`,
USCIB_Managed_Pkg.SetDefaultContact(:p_spcontactid);
END;`,
{
p_spcontactid: {
val: body.p_spcontactid,
@ -138,20 +146,16 @@ export class SpContactsService {
await connection.commit();
return 'SP executed successfully';
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
}
}
finally {
return { statusCode: 200, message: 'Default contact was added successfully for SP' };
} catch (error) {
this.logger.error('setSPDefaultcontact 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);
}
}
}
@ -162,24 +166,24 @@ export class SpContactsService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.UpdateSPContacts(
:p_spcontactid,
:p_firstname,
:p_lastname,
:P_MIDDLEINITIAL,
:p_title,
:p_phoneno,
:p_mobileno,
:p_faxno,
:p_emailaddress,
:p_user_id,
:p_cursor);
END;`,
USCIB_Managed_Pkg.UpdateSPContacts(
:p_spcontactid,
:p_firstname,
:p_lastname,
:P_MIDDLEINITIAL,
:p_title,
:p_phoneno,
:p_mobileno,
:p_faxno,
:p_emailaddress,
:p_user_id,
:p_cursor);
END;`,
{
p_spcontactid: {
val: body.p_spcontactid,
@ -235,20 +239,25 @@ export class SpContactsService {
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) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
}
finally {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
this.logger.error('updateSPContacts 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);
}
}
}
@ -259,13 +268,13 @@ export class SpContactsService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.InActivateSPContacts(:p_spcontactid);
END;`,
USCIB_Managed_Pkg.InActivateSPContacts(:p_spcontactid);
END;`,
{
p_spcontactid: {
val: body.p_spcontactid,
@ -276,20 +285,16 @@ export class SpContactsService {
await connection.commit();
return 'SP executed successfully';
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
}
}
finally {
return { statusCode: 200, message: 'Inactivated SP contact successfully' };
} catch (error) {
this.logger.error('inactivateSPContact 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);
}
}
}
@ -301,13 +306,13 @@ export class SpContactsService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.GetSPDefaultContacts(:p_SPid,:p_cursor);
END;`,
USCIB_Managed_Pkg.GetSPDefaultContacts(:p_SPid,:p_cursor);
END;`,
{
p_SPid: {
val: body.p_SPid,
@ -334,23 +339,19 @@ export class SpContactsService {
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
throw new BadRequestException();
}
return rows;
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
}
}
finally {
} catch (error) {
this.logger.error('getSPDefaultcontacts 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);
}
}
}
@ -363,7 +364,7 @@ export class SpContactsService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
throw new InternalServerException();
}
const result = await connection.execute(
@ -396,25 +397,21 @@ export class SpContactsService {
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
throw new BadRequestException();
}
return rows;
} catch (err) {
if (err instanceof Error) {
return { error: err.message };
} else {
return { error: 'An unknown error occurred' };
}
}
finally {
} catch (error) {
this.logger.error('getSPAllContacts 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);
}
}
}
}
}
}

View File

@ -20,7 +20,6 @@ export class SpService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
this.logger.error(`Database connection failed`);
throw new InternalServerException();
}
@ -132,11 +131,9 @@ export class SpService {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
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 {
@ -190,7 +187,6 @@ export class SpService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
this.logger.error(`Database connection failed`);
throw new InternalServerException();
}
@ -307,11 +303,9 @@ export class SpService {
return fres;
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
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 {
@ -331,7 +325,6 @@ export class SpService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
this.logger.error(`Database connection failed`);
throw new InternalServerException();
}
@ -362,7 +355,6 @@ 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);
}
@ -372,11 +364,9 @@ export class SpService {
}
} catch (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
throw new BadRequestException();
}
this.logger.error('getAllServiceproviders failed', error.stack || error);
throw new InternalServerException();
} finally {
@ -396,7 +386,6 @@ export class SpService {
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
this.logger.error(`Database connection failed`);
throw new InternalServerException();
}
@ -434,16 +423,17 @@ export class SpService {
}
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 (error) {
if (error instanceof BadRequestException) {
this.logger.warn(error.message);
throw error;
}
else if (error.message === "NJS-107: invalid cursor") {
this.logger.warn(error.message);
throw new BadRequestException();
}
this.logger.error('getServiceproviderByID failed', error.stack || error);