From 1e0e177fd04620fc9387c9b22e1279d2110a83a0 Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Fri, 16 May 2025 15:32:20 +0530 Subject: [PATCH] modified responses and error handling for oracle api --- src/mssql/manage-fee/manage-fee.controller.ts | 36 +- .../manage-clients/manage-clients.service.ts | 12 +- src/oracle/manage-fee/manage-fee.service.ts | 1838 +++++++++-------- src/oracle/param-table/param-table.service.ts | 12 +- .../carnet-sequence.service.ts | 4 +- .../uscib-managed-sp/region/region.service.ts | 8 +- .../sp-contacts/sp-contacts.service.ts | 4 +- src/oracle/uscib-managed-sp/sp/sp.service.ts | 6 +- 8 files changed, 963 insertions(+), 957 deletions(-) diff --git a/src/mssql/manage-fee/manage-fee.controller.ts b/src/mssql/manage-fee/manage-fee.controller.ts index ed6175d..39a482a 100644 --- a/src/mssql/manage-fee/manage-fee.controller.ts +++ b/src/mssql/manage-fee/manage-fee.controller.ts @@ -8,58 +8,58 @@ export class ManageFeeController { constructor(private readonly manageFeeService: ManageFeeService) { } - // @ApiTags('Manage Fee - Mssql') - // @Get('/GetBasicFeeRates') + @ApiTags('Manage Fee - Mssql') + @Get('/GetBasicFeeRates') GetBasicFeeRates(@Query() body: GetFeeGeneralDTO) { return this.manageFeeService.GETBASICFEERATES(body); } - // @ApiTags('Manage Fee - Mssql') - // @Post('/CreateBasicFee') + @ApiTags('Manage Fee - Mssql') + @Post('/CreateBasicFee') CreateBasicFee(@Body() body: CreateBasicFeeDTO) { return this.manageFeeService.CREATEBASICFEE(body); } - // @ApiTags('Manage Fee - Mssql') - // @Patch('/UpdateBasicFee') + @ApiTags('Manage Fee - Mssql') + @Patch('/UpdateBasicFee') UpdateBasicFee(@Body() body: UpdateBasicFeeDTO) { return this.manageFeeService.UPDATEBASICFEE(body); } - // @ApiTags('Manage Fee - Mssql') - // @Get('/GetBondRates') + @ApiTags('Manage Fee - Mssql') + @Get('/GetBondRates') GetBondRates(@Query() body: GetFeeGeneralDTO) { return this.manageFeeService.GETBONDRATES(body); } - // @ApiTags('Manage Fee - Mssql') - // @Post('/CreateBondRate') + @ApiTags('Manage Fee - Mssql') + @Post('/CreateBondRate') CreateBondRate(@Body() body: CreateBondRateDTO) { return this.manageFeeService.CREATEBONDRATE(body); } - // @ApiTags('Manage Fee - Mssql') - // @Patch('/UpdateBondRate') + @ApiTags('Manage Fee - Mssql') + @Patch('/UpdateBondRate') UpdateBondRate(@Body() body: UpdateBondRateDTO) { return this.manageFeeService.UPDATEBONDRATE(body); } // Cargo Rate - // @ApiTags('Manage Fee - Mssql') - // @Get('/GetCargoRates') + @ApiTags('Manage Fee - Mssql') + @Get('/GetCargoRates') GetCargoRates(@Query() body: GetFeeGeneralDTO) { return this.manageFeeService.GETCARGORATES(body); } - // @ApiTags('Manage Fee - Mssql') - // @Post('/CreateCargoRate') + @ApiTags('Manage Fee - Mssql') + @Post('/CreateCargoRate') CreateCargoRate(@Body() body: CreateCargoRateDTO) { return this.manageFeeService.CREATECARGORATE(body); } - // @ApiTags('Manage Fee - Mssql') - // @Patch('/UpdateCargoRate') + @ApiTags('Manage Fee - Mssql') + @Patch('/UpdateCargoRate') UpdateCargoRate(@Body() body: UpdateCargoRateDTO) { return this.manageFeeService.UPDATECARGORATE(body); } diff --git a/src/oracle/manage-clients/manage-clients.service.ts b/src/oracle/manage-clients/manage-clients.service.ts index ae482ff..9db1b66 100644 --- a/src/oracle/manage-clients/manage-clients.service.ts +++ b/src/oracle/manage-clients/manage-clients.service.ts @@ -325,7 +325,7 @@ export class ManageClientsService { // throw new Error('No cursor returned from the stored procedure'); // } - if (p_clientcursor_rows[0].ERRORMESG) { + if (p_clientcursor_rows.length>0 && p_clientcursor_rows[0].ERRORMESG) { throw new BadRequestException(p_clientcursor_rows[0].ERRORMESG); } @@ -477,7 +477,7 @@ export class ManageClientsService { throw new Error('No cursor returned from the stored procedure'); } - if (p_cursor_rows[0].ERRORMESG) { + if (p_cursor_rows.length>0 && p_cursor_rows[0].ERRORMESG) { throw new BadRequestException(p_cursor_rows[0].ERRORMESG); } @@ -629,7 +629,7 @@ export class ManageClientsService { throw new Error('No cursor returned from the stored procedure'); } - if (p_cursor_rows[0].ERRORMESG) { + if (p_cursor_rows.length>0 && p_cursor_rows[0].ERRORMESG) { throw new BadRequestException(p_cursor_rows[0].ERRORMESG); } @@ -774,7 +774,7 @@ export class ManageClientsService { throw new Error('No cursor returned from the stored procedure'); } - if (p_cursor_rows[0].ERRORMESG) { + if (p_cursor_rows.length>0 && p_cursor_rows[0].ERRORMESG) { throw new BadRequestException(p_cursor_rows[0].ERRORMESG); } @@ -950,7 +950,7 @@ export class ManageClientsService { throw new InternalServerException('No cursor returned from the stored procedure'); } - if (p_cursor_rows[0].ERRORMESG) { + if (p_cursor_rows.length>0 && p_cursor_rows[0].ERRORMESG) { throw new BadRequestException(p_cursor_rows[0].ERRORMESG); } @@ -1119,7 +1119,7 @@ export class ManageClientsService { throw new Error('No cursor returned from the stored procedure'); } - if (p_cursor_rows[0].ERRORMESG) { + if (p_cursor_rows.length>0 && p_cursor_rows[0].ERRORMESG) { throw new BadRequestException(p_cursor_rows[0].ERRORMESG); } diff --git a/src/oracle/manage-fee/manage-fee.service.ts b/src/oracle/manage-fee/manage-fee.service.ts index 4c2f287..1d11918 100644 --- a/src/oracle/manage-fee/manage-fee.service.ts +++ b/src/oracle/manage-fee/manage-fee.service.ts @@ -28,7 +28,7 @@ export class ManageFeeService { constructor(private readonly oracleDBService: OracleDBService) { } - // get + // basic fee async GETBASICFEERATES(body: GetFeeGeneralDTO): Promise { let connection; @@ -105,463 +105,6 @@ export class ManageFeeService { } } - async GETBONDRATES(body: GetFeeGeneralDTO): Promise { - let connection; - let rows: any = []; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.GETBONDRATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); - END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - rows = rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - throw new BadRequestException() - } - - console.warn(rows); - - - if (rows.length>0 && rows[0].ERRORMESG) { - console.log(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('GETBONDRATES failed', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - async GETCARGORATES(body: GetFeeGeneralDTO): Promise { - let connection; - let rows: any = []; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.GETCARGORATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); - END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - rows = rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - 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 (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); - throw new InternalServerException(); - } finally { - // Ensure connection is closed - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - - } - - async GETCFFEERATES(body: GetFeeGeneralDTO): Promise { - let connection; - let rows: any = []; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.GETCFFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); - END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - rows = rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - 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 (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); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - async GETCSFEERATES(body: GetFeeGeneralDTO): Promise { - let connection; - let rows: any = []; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.GETCSFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); - END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - rows = rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - throw new BadRequestException(); - } - - if (rows.length>0 && rows[0].ERRORMESG) { - console.log(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('GETCSFEERATES failed', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - async GETEFFEERATES(body: GetFeeGeneralDTO): Promise { - let connection; - let rows: any = []; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.GETEFFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); - END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - rows = rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - throw new BadRequestException(); - } - - if (rows.length>0 && rows[0].ERRORMESG) { - console.log(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('GETEFFEERATES failed', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - async GETFEECOMM(body: GetFeeGeneralDTO): Promise { - let connection; - let rows: any = []; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.GETFEECOMM(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); - END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ACTIVE_INACTIVE: { - val: body.P_ACTIVE_INACTIVE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - - if (result.outBinds && result.outBinds.p_cursor) { - const cursor = result.outBinds.p_cursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - rows = rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - throw new BadRequestException(); - } - - if (rows.length>0 && rows[0].ERRORMESG) { - console.log(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('GETFEECOMM failed\n', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - // post - async CREATEBASICFEE(body: CreateBasicFeeDTO) { let connection; try { @@ -621,8 +164,8 @@ export class ManageFeeService { const fres = await result.outBinds.P_CURSOR.getRows(); - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } @@ -645,6 +188,158 @@ export class ManageFeeService { } } + async UPDATEBASICFEE(body: UpdateBasicFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.UPDATEBASICFEE( + :P_BASICFEESETUPID, + :P_FEES, + :P_EFFDATE, + :P_USERID, + :P_CURSOR); + END;`, + { + P_BASICFEESETUPID: { + val: body.P_BASICFEESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_FEES: { + val: body.P_FEES, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + + const fres = await result.outBinds.P_CURSOR.getRows(); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Updated Successfully" }; + } catch (error) { + if (error instanceof BadRequestException) { + this.logger.warn(error.message); + throw error; + } + this.logger.error('UPDATEBASICFEE failed', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + + // bond rate + + async GETBONDRATES(body: GetFeeGeneralDTO): Promise { + let connection; + let rows: any = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.GETBONDRATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); + END;`, + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } else { + throw new BadRequestException() + } + + console.warn(rows); + + + if (rows.length > 0 && rows[0].ERRORMESG) { + console.log(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('GETBONDRATES failed', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + async CREATEBONDRATE(body: CreateBondRateDTO) { let connection; try { @@ -713,8 +408,8 @@ export class ManageFeeService { const fres = await result.outBinds.P_CURSOR.getRows(); - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } @@ -737,6 +432,157 @@ export class ManageFeeService { } } + async UPDATEBONDRATE(body: UpdateBondRateDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.UPDATEBONDRATE( + :P_BONDRATESETUPID, + :P_RATE, + :P_EFFDATE, + :P_USERID, + :P_CURSOR); + END;`, + { + P_BONDRATESETUPID: { + val: body.P_BONDRATESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_RATE: { + val: body.P_RATE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + + const fres = await result.outBinds.P_CURSOR.getRows(); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Updated Successfully" }; + } catch (error) { + if (error instanceof BadRequestException) { + this.logger.warn(error.message); + throw error; + } + this.logger.error('UPDATEBONDRATE failed', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + + // cargo rate + + async GETCARGORATES(body: GetFeeGeneralDTO): Promise { + let connection; + let rows: any = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.GETCARGORATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); + END;`, + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } else { + 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 (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); + throw new InternalServerException(); + } finally { + // Ensure connection is closed + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + + } + async CREATECARGORATE(body: CreateCargoRateDTO) { let connection; try { @@ -800,8 +646,8 @@ export class ManageFeeService { const fres = await result.outBinds.P_CURSOR.getRows(); - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } @@ -824,6 +670,155 @@ export class ManageFeeService { } } + async UPDATECARGORATE(body: UpdateCargoRateDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.UPDATECARGORATE( + :P_CARGORATESETUPID, + :P_RATE, + :P_EFFDATE, + :P_USERID, + :P_CURSOR); + END;`, + { + P_CARGORATESETUPID: { + val: body.P_CARGORATESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_RATE: { + val: body.P_RATE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + + const fres = await result.outBinds.P_CURSOR.getRows(); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Updated Successfully" }; + } catch (error) { + if (error instanceof BadRequestException) { + this.logger.warn(error.message); + throw error; + } + this.logger.error('UPDATECARGORATE failed', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + + // counter foil + + async GETCFFEERATES(body: GetFeeGeneralDTO): Promise { + let connection; + let rows: any = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.GETCFFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); + END;`, + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } else { + 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 (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); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + async CREATECFFEE(body: CreateCfFeeDTO) { let connection; try { @@ -892,8 +887,8 @@ export class ManageFeeService { const fres = await result.outBinds.P_CURSOR.getRows(); - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } @@ -916,6 +911,156 @@ export class ManageFeeService { } } + async UPDATECFFEE(body: UpdateCfFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.UPDATECFFEE( + :P_CFFEESETUPID, + :P_RATE, + :P_EFFDATE, + :P_USERID, + :P_CURSOR); + END;`, + { + P_CFFEESETUPID: { + val: body.P_CFFEESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_RATE: { + val: body.P_RATE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + + const fres = await result.outBinds.P_CURSOR.getRows(); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Updated Successfully" }; + } catch (error) { + if (error instanceof BadRequestException) { + this.logger.warn(error.message); + throw error; + } + this.logger.error('UPDATECFFEE failed', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + + + // continuation sheet + + async GETCSFEERATES(body: GetFeeGeneralDTO): Promise { + let connection; + let rows: any = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.GETCSFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); + END;`, + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } else { + throw new BadRequestException(); + } + + if (rows.length > 0 && rows[0].ERRORMESG) { + console.log(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('GETCSFEERATES failed', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + async CREATECSFEE(body: CreateCsFeeDTO) { let connection; try { @@ -974,8 +1119,8 @@ export class ManageFeeService { const fres = await result.outBinds.P_CURSOR.getRows(); - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } @@ -998,6 +1143,155 @@ export class ManageFeeService { } } + async UPDATECSFEE(body: UpdateCsFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.UPDATECSFEE( + :P_CSFEESETUPID, + :P_RATE, + :P_EFFDATE, + :P_USERID, + :P_CURSOR); + END;`, + { + P_CSFEESETUPID: { + val: body.P_CSFEESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_RATE: { + val: body.P_RATE, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + + const fres = await result.outBinds.P_CURSOR.getRows(); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Updated Successfully" }; + } catch (error) { + if (error instanceof BadRequestException) { + this.logger.warn(error.message); + throw error; + } + this.logger.error('UPDATECSFEE failed', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + + // expedited fee + + async GETEFFEERATES(body: GetFeeGeneralDTO): Promise { + let connection; + let rows: any = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.GETEFFEERATES(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); + END;`, + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } else { + throw new BadRequestException(); + } + + if (rows.length > 0 && rows[0].ERRORMESG) { + console.log(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('GETEFFEERATES failed', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + async CREATEEFFEE(body: CreateEfFeeDTO) { let connection; try { @@ -1072,8 +1366,8 @@ export class ManageFeeService { const fres = await result.outBinds.P_CURSOR.getRows(); - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } @@ -1096,6 +1390,155 @@ export class ManageFeeService { } } + async UPDATEEFFEE(body: UpdateEfFeeDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.UPDATEEFFEE( + :P_EFFEESETUPID, + :P_FEES, + :P_EFFDATE, + :P_USERID, + :P_CURSOR); + END;`, + { + P_EFFEESETUPID: { + val: body.P_EFFEESETUPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_FEES: { + val: body.P_FEES, + type: oracledb.DB_TYPE_NUMBER, + }, + P_EFFDATE: { + val: body.P_EFFDATE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_USERID: { + val: body.P_USERID, + type: oracledb.DB_TYPE_NVARCHAR, + }, + P_CURSOR: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + await connection.commit(); + + const fres = await result.outBinds.P_CURSOR.getRows(); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Updated Successfully" }; + } catch (error) { + if (error instanceof BadRequestException) { + this.logger.warn(error.message); + throw error; + } + this.logger.error('UPDATEEFFEE failed', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + + // fee comm + + async GETFEECOMM(body: GetFeeGeneralDTO): Promise { + let connection; + let rows: any = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + this.logger.error(`Database connection failed`); + throw new InternalServerException(); + } + + const result = await connection.execute( + `BEGIN + MANAGEFEE_SETUP_PKG.GETFEECOMM(:P_SPID,:P_ACTIVE_INACTIVE,:p_cursor); + END;`, + { + P_SPID: { + val: body.P_SPID, + type: oracledb.DB_TYPE_NUMBER, + }, + P_ACTIVE_INACTIVE: { + val: body.P_ACTIVE_INACTIVE, + type: oracledb.DB_TYPE_NVARCHAR, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } else { + throw new BadRequestException(); + } + + if (rows.length > 0 && rows[0].ERRORMESG) { + console.log(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('GETFEECOMM failed\n', error.stack || error); + throw new InternalServerException(); + } finally { + if (connection) { + try { + await connection.close(); + } catch (closeErr) { + this.logger.error('Failed to close DB connection', closeErr); + } + } + } + } + async CREATEFEECOMM(body: CreateFeeCommDTO) { let connection; try { @@ -1149,7 +1592,7 @@ export class ManageFeeService { const fres = await result.outBinds.P_CURSOR.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length > 0 && fres[0].ERRORMESG) { this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } @@ -1173,440 +1616,6 @@ export class ManageFeeService { } } - // update - - async UPDATEBASICFEE(body: UpdateBasicFeeDTO) { - let connection; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.UPDATEBASICFEE( - :P_BASICFEESETUPID, - :P_FEES, - :P_EFFDATE, - :P_USERID, - :P_CURSOR); - END;`, - { - P_BASICFEESETUPID: { - val: body.P_BASICFEESETUPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_FEES: { - val: body.P_FEES, - type: oracledb.DB_TYPE_NUMBER, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - await connection.commit(); - - const fres = await result.outBinds.P_CURSOR.getRows(); - - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); - throw new BadRequestException(fres[0].ERRORMESG) - } - - return { statusCode: 200, message: "Updated Successfully" }; - } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('UPDATEBASICFEE failed', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - async UPDATEBONDRATE(body: UpdateBondRateDTO) { - let connection; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.UPDATEBONDRATE( - :P_BONDRATESETUPID, - :P_RATE, - :P_EFFDATE, - :P_USERID, - :P_CURSOR); - END;`, - { - P_BONDRATESETUPID: { - val: body.P_BONDRATESETUPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - await connection.commit(); - - const fres = await result.outBinds.P_CURSOR.getRows(); - - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); - throw new BadRequestException(fres[0].ERRORMESG) - } - - return { statusCode: 200, message: "Updated Successfully" }; - } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('UPDATEBONDRATE failed', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - async UPDATECARGORATE(body: UpdateCargoRateDTO) { - let connection; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.UPDATECARGORATE( - :P_CARGORATESETUPID, - :P_RATE, - :P_EFFDATE, - :P_USERID, - :P_CURSOR); - END;`, - { - P_CARGORATESETUPID: { - val: body.P_CARGORATESETUPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - await connection.commit(); - - const fres = await result.outBinds.P_CURSOR.getRows(); - - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); - throw new BadRequestException(fres[0].ERRORMESG) - } - - return { statusCode: 200, message: "Updated Successfully" }; - } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('UPDATECARGORATE failed', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - async UPDATECFFEE(body: UpdateCfFeeDTO) { - let connection; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.UPDATECFFEE( - :P_CFFEESETUPID, - :P_RATE, - :P_EFFDATE, - :P_USERID, - :P_CURSOR); - END;`, - { - P_CFFEESETUPID: { - val: body.P_CFFEESETUPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - await connection.commit(); - - const fres = await result.outBinds.P_CURSOR.getRows(); - - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); - throw new BadRequestException(fres[0].ERRORMESG) - } - - return { statusCode: 200, message: "Updated Successfully" }; - } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('UPDATECFFEE failed', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - async UPDATECSFEE(body: UpdateCsFeeDTO) { - let connection; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.UPDATECSFEE( - :P_CSFEESETUPID, - :P_RATE, - :P_EFFDATE, - :P_USERID, - :P_CURSOR); - END;`, - { - P_CSFEESETUPID: { - val: body.P_CSFEESETUPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - await connection.commit(); - - const fres = await result.outBinds.P_CURSOR.getRows(); - - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); - throw new BadRequestException(fres[0].ERRORMESG) - } - - return { statusCode: 200, message: "Updated Successfully" }; - } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('UPDATECSFEE failed', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - - async UPDATEEFFEE(body: UpdateEfFeeDTO) { - let connection; - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - this.logger.error(`Database connection failed`); - throw new InternalServerException(); - } - - const result = await connection.execute( - `BEGIN - MANAGEFEE_SETUP_PKG.UPDATEEFFEE( - :P_EFFEESETUPID, - :P_FEES, - :P_EFFDATE, - :P_USERID, - :P_CURSOR); - END;`, - { - P_EFFEESETUPID: { - val: body.P_EFFEESETUPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_FEES: { - val: body.P_FEES, - type: oracledb.DB_TYPE_NUMBER, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, - ); - await connection.commit(); - - const fres = await result.outBinds.P_CURSOR.getRows(); - - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); - throw new BadRequestException(fres[0].ERRORMESG) - } - - return { statusCode: 200, message: "Updated Successfully" }; - } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('UPDATEEFFEE failed', error.stack || error); - throw new InternalServerException(); - } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - } - async UPDATEFEECOMM(body: UpdateFeeCommDTO) { let connection; try { @@ -1653,20 +1662,15 @@ export class ManageFeeService { ); await connection.commit(); - if (result.outBinds && result.outBinds.P_CURSOR) { - const fres = await result.outBinds.P_CURSOR.getRows(); + const fres = await result.outBinds.P_CURSOR.getRows(); - console.log('pcursor: ', fres); - - if (fres[0].ERRORMESG) { - console.log(fres[0].ERRORMESG); - throw new BadRequestException(fres[0].ERRORMESG) - } - - return { statusCode: 200, message: "Updated Successfully" }; - } else { - throw new BadRequestException(); + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } + + return { statusCode: 200, message: "Updated Successfully" }; + } catch (error) { if (error instanceof BadRequestException) { this.logger.warn(error.message); diff --git a/src/oracle/param-table/param-table.service.ts b/src/oracle/param-table/param-table.service.ts index cb3f119..5f7d348 100644 --- a/src/oracle/param-table/param-table.service.ts +++ b/src/oracle/param-table/param-table.service.ts @@ -126,12 +126,12 @@ export class ParamTableService { const fres = await result.outBinds.p_cursor.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } - return fres; + return { statusCode: 201, message: "Createdted Successfully", ...fres[0] }; } catch (error) { if (error instanceof BadRequestException) { this.logger.warn(error.message); @@ -233,12 +233,12 @@ export class ParamTableService { const fres = await result.outBinds.p_cursor.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } - return fres; + return { statusCode: 201, message: "Createdted Successfully", ...fres[0] }; } catch (error) { if (error instanceof BadRequestException) { throw error; @@ -337,12 +337,12 @@ export class ParamTableService { const fres = await result.outBinds.p_cursor.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } - return fres; + return { statusCode: 200, message: "Updated Successfully", ...fres[0] }; } catch (error) { if (error instanceof BadRequestException) { this.logger.warn(error.message); diff --git a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts index 348859f..533cde3 100644 --- a/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts +++ b/src/oracle/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts @@ -70,12 +70,12 @@ export class CarnetSequenceService { await result.outBinds.p_cursor.close(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } - return fres; + return { statusCode: 201, message: "Createdted Successfully", ...fres[0] }; } catch (error) { if (error instanceof BadRequestException) { this.logger.warn(error.message); diff --git a/src/oracle/uscib-managed-sp/region/region.service.ts b/src/oracle/uscib-managed-sp/region/region.service.ts index 56f6289..a394319 100644 --- a/src/oracle/uscib-managed-sp/region/region.service.ts +++ b/src/oracle/uscib-managed-sp/region/region.service.ts @@ -129,12 +129,12 @@ export class RegionService { const fres = await result.outBinds.p_cursor.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } - return fres; + return { statusCode: 201, message: "Createdted Successfully", ...fres[0] }; } catch (error) { if (error instanceof BadRequestException) { this.logger.warn(error.message); @@ -188,12 +188,12 @@ export class RegionService { const fres = await result.outBinds.p_cursor.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } - return fres; + return { statusCode: 200, message: "Updated Successfully", ...fres[0] }; } catch (error) { if (error instanceof BadRequestException) { this.logger.warn(error.message); diff --git a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts index 04daf07..5895981 100644 --- a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts +++ b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts @@ -101,7 +101,7 @@ export class SpContactsService { const fres = await result.outBinds.p_cursor.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } @@ -239,7 +239,7 @@ export class SpContactsService { const fres = await result.outBinds.p_cursor.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } diff --git a/src/oracle/uscib-managed-sp/sp/sp.service.ts b/src/oracle/uscib-managed-sp/sp/sp.service.ts index d229a40..af941c6 100644 --- a/src/oracle/uscib-managed-sp/sp/sp.service.ts +++ b/src/oracle/uscib-managed-sp/sp/sp.service.ts @@ -124,7 +124,8 @@ export class SpService { const fres = await result.outBinds.p_cursor.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) } @@ -296,7 +297,8 @@ export class SpService { const fres = await result.outBinds.p_cursor.getRows(); - if (fres[0].ERRORMESG) { + if (fres.length>0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); throw new BadRequestException(fres[0].ERRORMESG) }