From 06ccbec9373adca72be4f4028df5096e1ad4b4e9 Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Mon, 19 May 2025 16:23:56 +0530 Subject: [PATCH] mssql fee updated --- src/mssql/manage-fee/manage-fee.controller.ts | 48 +++--- src/mssql/manage-fee/manage-fee.service.ts | 144 ++++++++++++++---- 2 files changed, 140 insertions(+), 52 deletions(-) diff --git a/src/mssql/manage-fee/manage-fee.controller.ts b/src/mssql/manage-fee/manage-fee.controller.ts index 39a482a..188ac27 100644 --- a/src/mssql/manage-fee/manage-fee.controller.ts +++ b/src/mssql/manage-fee/manage-fee.controller.ts @@ -66,80 +66,80 @@ export class ManageFeeController { // Counter Foil - // @ApiTags('Manage Fee - Mssql') - // @Get('/GetCfFeeRates') + @ApiTags('Manage Fee - Mssql') + @Get('/GetCfFeeRates') GetCfFeeRates(@Query() body: GetFeeGeneralDTO) { return this.manageFeeService.GETCFFEERATES(body); } - // @ApiTags('Manage Fee - Mssql') - // @Post('/CreateCfFee') + @ApiTags('Manage Fee - Mssql') + @Post('/CreateCfFee') CreateCfFee(@Body() body: CreateCfFeeDTO) { return this.manageFeeService.CREATECFFEE(body); } - // @ApiTags('Manage Fee - Mssql') - // @Patch('/UpdateCfFee') + @ApiTags('Manage Fee - Mssql') + @Patch('/UpdateCfFee') UpdateCfFee(@Body() body: UpdateCfFeeDTO) { return this.manageFeeService.UPDATECFFEE(body); } // Continuation sheet - // @ApiTags('Manage Fee - Mssql') - // @Get('/GetCsFeeRates') + @ApiTags('Manage Fee - Mssql') + @Get('/GetCsFeeRates') GetCsFeeRates(@Query() body: GetFeeGeneralDTO) { return this.manageFeeService.GETCSFEERATES(body); } - // @ApiTags('Manage Fee - Mssql') - // @Post('/CreateCsFee') + @ApiTags('Manage Fee - Mssql') + @Post('/CreateCsFee') CreateCsFee(@Body() body: CreateCsFeeDTO) { return this.manageFeeService.CREATECSFEE(body); } - // @ApiTags('Manage Fee - Mssql') - // @Patch('/UpdateCsFee') + @ApiTags('Manage Fee - Mssql') + @Patch('/UpdateCsFee') UpdateCsFee(@Body() body: UpdateCsFeeDTO) { return this.manageFeeService.UPDATECSFEE(body); } // Expedited Fee - // @ApiTags('Manage Fee - Mssql') - // @Get('/GetEfFeeRates') + @ApiTags('Manage Fee - Mssql') + @Get('/GetEfFeeRates') GetEfFeeRates(@Query() body: GetFeeGeneralDTO) { return this.manageFeeService.GETEFFEERATES(body); } - // @ApiTags('Manage Fee - Mssql') - // @Post('/CreateEfFee') + @ApiTags('Manage Fee - Mssql') + @Post('/CreateEfFee') CreateEeFee(@Body() body: CreateEfFeeDTO) { return this.manageFeeService.CREATEEFFEE(body); } - // @ApiTags('Manage Fee - Mssql') - // @Patch('/UpdateEfFee') + @ApiTags('Manage Fee - Mssql') + @Patch('/UpdateEfFee') UpdateEfFee(@Body() body: UpdateEfFeeDTO) { return this.manageFeeService.UPDATEEFFEE(body); } // Fee Comm - // @ApiTags('Manage Fee - Mssql') - // @Get('/GetFeeComm') + @ApiTags('Manage Fee - Mssql') + @Get('/GetFeeComm') GetFeeComm(@Query() body: GetFeeGeneralDTO) { return this.manageFeeService.GETFEECOMM(body); } - // @ApiTags('Manage Fee - Mssql') - // @Post('/CreateFeeComm') + @ApiTags('Manage Fee - Mssql') + @Post('/CreateFeeComm') CreateFeeComm(@Body() body: CreateFeeCommDTO) { return this.manageFeeService.CREATEFEECOMM(body); } - // @ApiTags('Manage Fee - Mssql') - // @Patch('/UpdateFeeComm') + @ApiTags('Manage Fee - Mssql') + @Patch('/UpdateFeeComm') UpdateFeeComm(@Body() body: UpdateFeeCommDTO) { return this.manageFeeService.UPDATEFEECOMM(body); } diff --git a/src/mssql/manage-fee/manage-fee.service.ts b/src/mssql/manage-fee/manage-fee.service.ts index 2a0f507..ed13fe0 100644 --- a/src/mssql/manage-fee/manage-fee.service.ts +++ b/src/mssql/manage-fee/manage-fee.service.ts @@ -1,8 +1,7 @@ import { Injectable, Logger } from '@nestjs/common'; -import { MssqlDBService, OracleDBService } from 'src/db/db.service'; +import { MssqlDBService } from 'src/db/db.service'; import { InternalServerException } from 'src/exceptions/internalServerError.exception'; import { CreateBasicFeeDTO, CreateBondRateDTO, CreateCargoRateDTO, CreateCfFeeDTO, CreateCsFeeDTO, CreateEfFeeDTO, CreateFeeCommDTO, GetFeeGeneralDTO, UpdateBasicFeeDTO, UpdateBondRateDTO, UpdateCargoRateDTO, UpdateCfFeeDTO, UpdateCsFeeDTO, UpdateEfFeeDTO, UpdateFeeCommDTO } from 'src/oracle/manage-fee/manage-fee.dto'; -import * as oracledb from 'oracledb'; import { BadRequestException } from 'src/exceptions/badRequest.exception'; import { Connection, Request } from 'mssql'; import * as mssql from 'mssql'; @@ -16,7 +15,7 @@ export class ManageFeeService { // Basic Fee Setup - async GETBASICFEERATES(body: GetFeeGeneralDTO): Promise { + async GETBASICFEERATES(body: GetFeeGeneralDTO): Promise { let connection: Connection; try { connection = await this.mssqlDBService.getConnection(); @@ -24,7 +23,14 @@ export class ManageFeeService { request.input('p_spid', mssql.Int, body.P_SPID); request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE); const result = await request.execute('carnetsys.GetBasicFeeRates'); - return result.recordset; + if (result.recordset) { + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return result.recordset; + } + throw new InternalServerException(); } catch (error) { throw new InternalServerException(); } @@ -42,7 +48,11 @@ export class ManageFeeService { request.input('P_FEES', mssql.Int, body.P_FEES); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.CreateBasicFee'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 201, message: "Created Successfully" }; } catch (error) { throw new InternalServerException(); } @@ -58,7 +68,11 @@ export class ManageFeeService { request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.UpdateBasicFee'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 200, message: "Updated Successfully" }; } catch (error) { throw new InternalServerException(); } @@ -66,7 +80,7 @@ export class ManageFeeService { // Bond Rate Setup - async GETBONDRATES(body: GetFeeGeneralDTO): Promise { + async GETBONDRATES(body: GetFeeGeneralDTO): Promise { let connection: Connection; try { @@ -75,8 +89,14 @@ export class ManageFeeService { request.input('p_spid', mssql.Int, body.P_SPID); request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE); const result = await request.execute('carnetsys.GetBondRates'); - return result.recordset; - + if (result.recordset) { + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return result.recordset; + } + throw new InternalServerException(); } catch (error) { console.log(error); @@ -100,7 +120,11 @@ export class ManageFeeService { request.input('P_RATE', mssql.Float, body.P_RATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.CreateBondRate'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 201, message: "Created Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); @@ -119,7 +143,11 @@ export class ManageFeeService { request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.UpdateBondRate'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 200, message: "Updated Successfully" }; } catch (error) { throw new InternalServerException(); } @@ -137,6 +165,10 @@ export class ManageFeeService { request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE); const result = await request.execute('carnetsys.GetCargoRates'); if (result.recordset) { + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } return result.recordset; } throw new BadRequestException(); @@ -161,7 +193,11 @@ export class ManageFeeService { request.input('P_RATE', mssql.Float, body.P_RATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.CreateCargoRate'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 201, message: "Created Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); @@ -178,7 +214,11 @@ export class ManageFeeService { request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.UpdateCargoRate'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 200, message: "Updated Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); @@ -197,6 +237,10 @@ export class ManageFeeService { request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE); const result = await request.execute('carnetsys.GetCFFeeRates'); if (result.recordset) { + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } return result.recordset; } throw new BadRequestException(); @@ -223,7 +267,11 @@ export class ManageFeeService { request.input('P_RATE', mssql.Float, body.P_RATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.CreateCFFee'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 201, message: "Created Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); @@ -242,7 +290,11 @@ export class ManageFeeService { request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.UpdateCFFee'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 200, message: "Updated Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); @@ -260,6 +312,10 @@ export class ManageFeeService { request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE); const result = await request.execute('carnetsys.GetCSFeeRates'); if (result.recordset) { + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } return result.recordset; } throw new BadRequestException(); @@ -284,7 +340,11 @@ export class ManageFeeService { request.input('P_RATE', mssql.Float, body.P_RATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.CreateCSFee'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 201, message: "Created Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); @@ -302,7 +362,11 @@ export class ManageFeeService { request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.UpdateCSFee'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 200, message: "Updated Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); @@ -321,6 +385,10 @@ export class ManageFeeService { request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE); const result = await request.execute('carnetsys.GetEFFeeRates'); if (result.recordset) { + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } return result.recordset; } throw new BadRequestException(); @@ -347,25 +415,33 @@ export class ManageFeeService { request.input('P_FEES', mssql.Float, body.P_FEES); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.CreateEFFee'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 201, message: "Created Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); } } - async UPDATEEFFEE(body: UpdateEfFeeDTO) { - + async UPDATEEFFEE(body: UpdateEfFeeDTO) { + let connection: Connection; try { connection = await this.mssqlDBService.getConnection(); const request = new Request(connection); request.input('P_EFFEESETUPID', mssql.Int, body.P_EFFEESETUPID); - request.input('P_FEES', mssql.Float, body.P_FEES); + request.input('P_FEES', mssql.Float, body.P_FEES); request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.UpdateEFFee'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 200, message: "Updated Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); @@ -384,12 +460,16 @@ export class ManageFeeService { request.input('p_active_inactive', mssql.VarChar(8), body.P_ACTIVE_INACTIVE); const result = await request.execute('carnetsys.GetFeecomm'); if (result.recordset) { + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } return result.recordset; } throw new BadRequestException(); } catch (error) { console.log(error); - + if (error instanceof BadRequestException) { throw error } @@ -397,8 +477,8 @@ export class ManageFeeService { } } - async CREATEFEECOMM(body: CreateFeeCommDTO) { - + async CREATEFEECOMM(body: CreateFeeCommDTO) { + let connection: Connection; try { connection = await this.mssqlDBService.getConnection(); @@ -409,7 +489,11 @@ export class ManageFeeService { request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.CreateFeeComm'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 201, message: "Created Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); @@ -426,10 +510,14 @@ export class ManageFeeService { request.input('P_EFFDATE', mssql.VarChar(100), body.P_EFFDATE); request.input('P_USERID', mssql.VarChar(100), body.P_USERID); const result = await request.execute('carnetsys.UpdateFeeComm'); - return result.recordset; + if (result.recordset && result.recordset.length > 0 && result.recordset[0].ERRORMESG) { + this.logger.warn(`error from DB: ${result.recordset[0].ERRORMESG}`); + throw new BadRequestException(result.recordset[0].ERRORMESG); + } + return { statusCode: 200, message: "Updated Successfully" }; } catch (error) { console.log(error); throw new InternalServerException(); } - } + } }