diff --git a/src/dto/manage-holders/manage-holders.dto.ts b/src/dto/manage-holders/manage-holders.dto.ts index 9126bc3..9258bae 100644 --- a/src/dto/manage-holders/manage-holders.dto.ts +++ b/src/dto/manage-holders/manage-holders.dto.ts @@ -73,6 +73,7 @@ export class UpdateHolderContactDTO extends IntersectionType( USERID_DTO ) { } + export class GetHolderDTO extends IntersectionType( SPID_DTO, HOLDERID_DTO diff --git a/src/oracle/carnet-application/carnet-application.service.ts b/src/oracle/carnet-application/carnet-application.service.ts index 0c7cb3a..bed5c82 100644 --- a/src/oracle/carnet-application/carnet-application.service.ts +++ b/src/oracle/carnet-application/carnet-application.service.ts @@ -2,10 +2,9 @@ import { Injectable, Logger } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; import * as oracledb from 'oracledb' import { InternalServerException } from 'src/exceptions/internalServerError.exception'; -import { closeOracleDbConnection, fetchCursor, handleError } from 'src/utils/helper'; +import { closeOracleDbConnection, fetchCursor, handleError, setEmptyStringsToNull } from 'src/utils/helper'; import { - COUNTRYTABLE_DTO, COUNTRYTABLE_ROW_DTO, GLTABLE_DTO, GLTABLE_ROW_DTO, CarnetProcessingCenterDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO, CreateApplicationDTO, UpdateExpGoodsAuthRepDTO, @@ -62,15 +61,6 @@ export class CarnetApplicationService { const reqBody = JSON.parse(JSON.stringify(body)); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach((key) => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === '') { - obj[key] = null; - } - }); - } setEmptyStringsToNull(reqBody); @@ -198,8 +188,7 @@ export class CarnetApplicationService { P_AUTOFLAG: { val: body.P_AUTOFLAG, type: oracledb.DB_TYPE_VARCHAR }, P_HORSEFLAG: { val: body.P_HORSEFLAG, type: oracledb.DB_TYPE_VARCHAR }, P_AUTHREP: { val: body.P_AUTHREP, type: oracledb.DB_TYPE_VARCHAR }, - P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }, - // P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, + P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, P_USSETS: { val: body.P_USSETS, type: oracledb.DB_TYPE_NUMBER }, // P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: 'CARNETSYS.CARNETCOUNTRYTABLE' }, P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, diff --git a/src/oracle/home-page/home-page.controller.ts b/src/oracle/home-page/home-page.controller.ts index 413a6fa..fd3268b 100644 --- a/src/oracle/home-page/home-page.controller.ts +++ b/src/oracle/home-page/home-page.controller.ts @@ -8,7 +8,6 @@ import { HomePageService } from './home-page.service'; import { ApiTags } from '@nestjs/swagger'; import { - EMAIL_DTO, GetCarnetDetailsbyCarnetStatusDTO, SPID_DTO, USERID_DTO diff --git a/src/oracle/home-page/home-page.dto.ts b/src/oracle/home-page/home-page.dto.ts deleted file mode 100644 index 0268761..0000000 --- a/src/oracle/home-page/home-page.dto.ts +++ /dev/null @@ -1,363 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; -import { Type } from 'class-transformer'; -import { - IsArray, - IsDefined, - IsInt, - IsNumber, - IsOptional, - IsString, - Length, - Max, - Min, - ValidateNested, -} from 'class-validator'; - -// export class p_gltableDTO { -// @ApiProperty({ required: true }) -// @Max(999999999, { message: 'Property ItemNo must not exceed 999999999' }) -// @Min(0, { message: 'Property ItemNo must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property ItemNo must be a number' }) -// @IsDefined({ message: 'Property ItemNo is required' }) -// ItemNo: number; - -// @ApiProperty({ required: true }) -// @Length(0, 1000, { -// message: 'Property ItemDescription must be between 1 and 1000 characters', -// }) -// @IsString({ message: 'Property ItemDescription should be string' }) -// @IsDefined({ message: 'Property ItemDescription is required' }) -// ItemDescription: string; - -// @ApiProperty({ required: true }) -// @IsNumber({}, { message: 'Property ItemValue should be number' }) -// @IsDefined({ message: 'Property ItemValue is required' }) -// ItemValue: number; - -// @ApiProperty({ required: true }) -// @Max(99999999999, { -// message: 'Property Noofpieces must not exceed 99999999999', -// }) -// @Min(0, { message: 'Property Noofpieces must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property Noofpieces must be a number' }) -// @IsDefined({ message: 'Property Noofpieces is required' }) -// Noofpieces: number; - -// @ApiProperty({ required: false }) -// @IsNumber() -// @IsOptional() -// ItemWeight?: number; - -// @ApiProperty({ required: false }) -// @Length(0, 10, { -// message: 'Property ItemWeightUOM must be between 0 and 10 characters', -// }) -// @IsString() -// @IsOptional() -// ItemWeightUOM?: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property GoodsOriginCountry must be between 0 and 2 characters', -// }) -// @IsString({ message: 'Property GoodsOriginCountry should be string' }) -// @IsDefined({ message: 'Property name is required' }) -// GoodsOriginCountry: string; -// } - -// export class p_countrytableDTO { -// @ApiProperty({ required: true }) -// @Length(0, 1, { -// message: 'Property VisitTransitInd must be 0 to 1 characters', -// }) -// @IsString() -// @IsDefined({ message: 'Property VisitTransitInd is required' }) -// VisitTransitInd: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property CountryCode must be between 0 to 2 characters', -// }) -// @IsString() -// @IsDefined({ message: 'Property CountryCode is required' }) -// CountryCode: string; - -// @ApiProperty({ required: true }) -// @Max(999, { message: 'Property NoOfTimesEntLeave must not exceed 999' }) -// @Min(0, { message: 'Property NoOfTimesEntLeave must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property NoOfTimesEntLeave must be a number' }) -// @IsDefined({ message: 'Property NoOfTimesEntLeave is required' }) -// NoOfTimesEntLeave: number; -// } - -// export class SaveCarnetApplicationDTO { -// @ApiProperty({ required: true }) -// @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_spid must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// p_spid: number; - -// @ApiProperty({ required: true }) -// @Max(999999999, { message: 'Property p_clientid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_clientid must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_clientid must be a number' }) -// p_clientid: number; - -// @ApiProperty({ required: true }) -// @Max(999999999, { -// message: 'Property p_locationid must not exceed 999999999', -// }) -// @Min(0, { message: 'Property p_locationid must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_locationid must be a number' }) -// p_locationid: number; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_userid must be between 0 to 50 characters', -// }) -// @IsString() -// p_userid: string; - -// @ApiProperty({ required: false }) -// @Max(999999999, { message: 'Property p_headerid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_headerid must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_headerid must be a number' }) -// @IsOptional() -// p_headerid?: number; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_applicationname must be between 0 to 50 characters', -// }) -// @IsString() -// p_applicationname: string; - -// @ApiProperty({ required: false }) -// @Max(999999999, { message: 'Property p_holderid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_holderid must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_holderid must be a number' }) -// @IsOptional() -// p_holderid?: number; - -// @ApiProperty({ required: false }) -// @Length(0, 1, { -// message: -// 'Property p_commercialsampleflag must be between 0 to 1 characters', -// }) -// @IsString() -// @IsOptional() -// p_commercialsampleflag?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 1, { -// message: 'Property p_profequipmentflag must be between 0 to 1 characters', -// }) -// @IsString() -// @IsOptional() -// p_profequipmentflag?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 1, { -// message: 'Property p_exhibitionsfairflag must be between 0 to 1 characters', -// }) -// @IsString() -// @IsOptional() -// p_exhibitionsfairflag?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 1, { -// message: 'Property p_autoflag must be between 0 to 1 characters', -// }) -// @IsString() -// @IsOptional() -// p_autoflag?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 1, { -// message: 'Property p_horseflag must be between 0 to 1 characters', -// }) -// @IsString() -// @IsOptional() -// p_horseflag?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 200, { -// message: 'Property p_authrep must be between 0 to 200 characters', -// }) -// @IsString() -// @IsOptional() -// p_authrep?: string; - -// @ApiProperty({ required: false, type: () => [p_gltableDTO] }) -// @Type(() => p_gltableDTO) -// @ValidateNested({ each: true }) -// @IsArray() -// // @ArrayNotEmpty({message:"Property gltable should not be empty"}) -// @IsOptional() -// p_gltable?: p_gltableDTO[]; - -// @ApiProperty({ required: false }) -// @Max(99999, { message: 'Property p_ussets must not exceed 99999' }) -// @Min(0, { message: 'Property p_ussets must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_ussets must be a number' }) -// @IsOptional() -// p_ussets?: number; - -// @ApiProperty({ required: false, type: () => [p_countrytableDTO] }) -// @ValidateNested({ each: true }) -// @IsArray() -// @Type(() => p_countrytableDTO) -// @IsOptional() -// p_countrytable?: p_countrytableDTO[]; - -// @ApiProperty({ required: false }) -// @Length(0, 10, { -// message: 'Property p_shiptotype must be between 0 to 10 characters', -// }) -// @IsString() -// @IsOptional() -// p_shiptotype?: string; - -// @ApiProperty({ required: false }) -// @Max(999999999, { -// message: 'Property p_shipaddrid must not exceed 999999999', -// }) -// @Min(0, { message: 'Property p_shipaddrid must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_shipaddrid must be a number' }) -// @IsOptional() -// p_shipaddrid?: number; - -// @ApiProperty({ required: false }) -// @Length(0, 1, { -// message: 'Property p_formofsecurity must be between 0 to 1 characters', -// }) -// @IsString() -// @IsOptional() -// p_formofsecurity?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 10, { -// message: 'Property p_insprotection must be between 0 to 10 characters', -// }) -// @IsString() -// @IsOptional() -// p_insprotection?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 10, { -// message: 'Property p_ldiprotection must be between 0 to 10 characters', -// }) -// @IsString() -// @IsOptional() -// p_ldiprotection?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 10, { -// message: 'Property p_deliverytype must be between 0 to 10 characters', -// }) -// @IsString() -// @IsOptional() -// p_deliverytype?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 10, { -// message: 'Property p_deliverymethod must be between 0 to 10 characters', -// }) -// @IsString() -// @IsOptional() -// p_deliverymethod?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 10, { -// message: 'Property p_paymentmethod must be between 0 to 10 characters', -// }) -// @IsString() -// @IsOptional() -// p_paymentmethod?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 20, { -// message: 'Property p_custcourierno must be between 0 to 20 characters', -// }) -// @IsString() -// @IsOptional() -// p_custcourierno?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 20, { -// message: 'Property p_refno must be between 0 to 20 characters', -// }) -// @IsString() -// @IsOptional() -// p_refno?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 2000, { -// message: 'Property p_notes must be between 0 to 2000 characters', -// }) -// @IsString() -// @IsOptional() -// p_notes?: string; -// } - -// export class TransmitApplicationtoProcessDTO { -// @ApiProperty({ required: true }) -// @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_spid must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// p_spid: number; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_userid must be between 0 to 50 characters', -// }) -// @IsString() -// @IsDefined({ message: 'Property p_userid is required' }) -// p_userid: string; - -// @ApiProperty({ required: true }) -// @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_spid must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_headerid must be a number' }) -// @IsDefined({ message: 'Property p_headerid is required' }) -// p_headerid: number; -// } - -// export class GetCarnetDetailsbyCarnetStatusDTO { -// @ApiProperty({ required: true }) -// @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_spid must be at least 0 or more' }) -// @IsInt() -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// p_spid: number; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_userid must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_userid must be string' }) -// @IsDefined({ message: 'Property p_userid is required' }) -// p_userid: string; - -// @ApiProperty({ required: true }) -// @Length(0, 20, { -// message: 'Property p_CarnetStatus must be between 0 to 20 characters', -// }) -// @IsString() -// @IsDefined({ message: 'Property p_CarnetStatus is required' }) -// p_CarnetStatus: string; -// } diff --git a/src/oracle/home-page/home-page.service.ts b/src/oracle/home-page/home-page.service.ts index f19f785..b4d962d 100644 --- a/src/oracle/home-page/home-page.service.ts +++ b/src/oracle/home-page/home-page.service.ts @@ -1,890 +1,171 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, Logger } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; import * as oracledb from 'oracledb'; import { - EMAIL_DTO, GetCarnetDetailsbyCarnetStatusDTO, SPID_DTO, USERID_DTO } from 'src/dto/property.dto'; +import { closeOracleDbConnection, fetchCursor, handleError } from 'src/utils/helper'; +import { BadRequestException } from 'src/exceptions/badRequest.exception'; +import { InternalServerException } from 'src/exceptions/internalServerError.exception'; @Injectable() export class HomePageService { + private readonly logger = new Logger(HomePageService.name); + constructor(private readonly oracleDBService: OracleDBService) { } async GetHomePageData(params: SPID_DTO) { let connection; - let p_basic_details = []; - let p_contacts = []; - let p_sequence = []; - let p_fees_comm = []; - let p_bf_fee = []; - let p_cf_Fee = []; - let p_cont_sheet_fee = []; - let p_ef_fee = []; - let p_security_deposit = []; - let p_param = []; - let p_region = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result = await connection.execute( `BEGIN - USERLOGIN_PKG.GetHomePageData( - :P_SPID, - :p_basic_details_cur, - :p_contacts_cur, - :p_sequence_cur, - :p_fees_comm_cur, - :p_bf_fee_cur, - :p_cf_Fee_cur, - :p_cont_sheet_fee_cur, - :p_ef_fee_cur, - :p_security_deposit_cur, - :p_param_cur, - :p_region_cur + USERLOGIN_PKG.GETHOMEPAGEDATA( + :P_SPID, :P_BASIC_DETAILS_CUR, :P_CONTACTS_CUR, :P_SEQUENCE_CUR, + :P_FEES_COMM_CUR, :P_BF_FEE_CUR, :P_CF_FEE_CUR, :P_CONT_SHEET_FEE_CUR, + :P_EF_FEE_CUR, :P_SECURITY_DEPOSIT_CUR, :P_PARAM_CUR, :P_REGION_CUR ); - END;`, + END;`, { - P_SPID: { - val: params.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - p_basic_details_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_contacts_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_sequence_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_fees_comm_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_bf_fee_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_cf_Fee_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_cont_sheet_fee_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_ef_fee_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_security_deposit_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_param_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - p_region_cur: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, - }, - { - outFormat: oracledb.OUT_FORMAT_OBJECT, + P_SPID: { val: params.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + p_basic_details_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_contacts_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_sequence_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_fees_comm_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_bf_fee_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_cf_Fee_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_cont_sheet_fee_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_ef_fee_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_security_deposit_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_param_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + p_region_cur: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, + { outFormat: oracledb.OUT_FORMAT_OBJECT } ); - if (result.outBinds && result.outBinds.p_basic_details_cur) { - const cursor = result.outBinds.p_basic_details_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_basic_details = p_basic_details.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_contacts_cur) { - const cursor = result.outBinds.p_contacts_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_contacts = p_contacts.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_sequence_cur) { - const cursor = result.outBinds.p_sequence_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_sequence = p_sequence.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_fees_comm_cur) { - const cursor = result.outBinds.p_fees_comm_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_fees_comm = p_fees_comm.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_bf_fee_cur) { - const cursor = result.outBinds.p_bf_fee_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_bf_fee = p_bf_fee.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_cf_Fee_cur) { - const cursor = result.outBinds.p_cf_Fee_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_cf_Fee = p_cf_Fee.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_cont_sheet_fee_cur) { - const cursor = result.outBinds.p_cont_sheet_fee_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_cont_sheet_fee = p_cont_sheet_fee.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_ef_fee_cur) { - const cursor = result.outBinds.p_ef_fee_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_ef_fee = p_ef_fee.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_security_deposit_cur) { - const cursor = result.outBinds.p_security_deposit_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_security_deposit = p_security_deposit.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_param_cur) { - const cursor = result.outBinds.p_param_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_param = p_param.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } - - if (result.outBinds && result.outBinds.p_region_cur) { - const cursor = result.outBinds.p_region_cur; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_region = p_region.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); + const outBinds: any = result.outBinds; + if ( + !outBinds?.p_basic_details_cur || + !outBinds?.p_contacts_cur || + !outBinds?.p_sequence_cur || + !outBinds?.p_fees_comm_cur || + !outBinds?.p_bf_fee_cur || + !outBinds?.p_cf_Fee_cur || + !outBinds?.p_cont_sheet_fee_cur || + !outBinds?.p_ef_fee_cur || + !outBinds?.p_security_deposit_cur || + !outBinds?.p_param_cur || + !outBinds?.p_region_cur + ) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } const tableData = { - p_basic_details, - p_contacts, - p_sequence, - p_fees_comm, - p_bf_fee, - p_cf_Fee, - p_cont_sheet_fee, - p_ef_fee, - p_security_deposit, - p_param, - p_region, + p_basic_details: await fetchCursor(outBinds.p_basic_details_cur, HomePageService.name), + p_contacts: await fetchCursor(outBinds.p_contacts_cur, HomePageService.name), + p_sequence: await fetchCursor(outBinds.p_sequence_cur, HomePageService.name), + p_fees_comm: await fetchCursor(outBinds.p_fees_comm_cur, HomePageService.name), + p_bf_fee: await fetchCursor(outBinds.p_bf_fee_cur, HomePageService.name), + p_cf_Fee: await fetchCursor(outBinds.p_cf_Fee_cur, HomePageService.name), + p_cont_sheet_fee: await fetchCursor(outBinds.p_cont_sheet_fee_cur, HomePageService.name), + p_ef_fee: await fetchCursor(outBinds.p_ef_fee_cur, HomePageService.name), + p_security_deposit: await fetchCursor(outBinds.p_security_deposit_cur, HomePageService.name), + p_param: await fetchCursor(outBinds.p_param_cur, HomePageService.name), + p_region: await fetchCursor(outBinds.p_region_cur, HomePageService.name), }; - const output = {}; - - for (const key in tableData) { - // console.log(key); - - output[key] = tableData[key].map((obj) => { - const newObj = { ...obj }; - for (const innerKey in obj) { - if (key === 'p_fees_comm') { - if (innerKey.includes(' ')) { - // Check if the key has a space - const newKey = innerKey.replace(/ /g, '_').toUpperCase(); // Replace spaces and convert to uppercase - newObj[newKey] = obj[innerKey]; // Add the new key - delete newObj[innerKey]; // Remove the old key - } - } - } - return newObj; - }); - } - - return output; - } catch (err) { - if (err instanceof Error) { - return { error: err.message }; - } else { - return { error: 'An unknown error occurred' }; - } - } - finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - console.error('Failed to close connection:', closeErr); - } - } + return tableData; + } catch (error) { + handleError(error, HomePageService.name) + } finally { + await closeOracleDbConnection(connection, HomePageService.name) } } async GetCarnetSummaryData(body: USERID_DTO) { let connection; - let rows: any = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result = await connection.execute( `BEGIN USERLOGIN_PKG.GetCarnetSummaryData(:P_USERID,:P_CURSOR); END;`, { - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + 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, - }, + 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 Error('No cursor returned from the stored procedure'); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - rows = rows.map((obj) => { - // Create a new object to hold the modified keys - const newObj = {}; + const fres: any = await fetchCursor(outBinds.P_CURSOR, HomePageService.name); - // Iterate over the keys of the current object - for (const key in obj) { - // Replace spaces with underscores in the key - const newKey = key.replace(/ /g, '_'); - newObj[newKey] = obj[key]; - } - - return newObj; - }); - - rows = rows.reduce((acc, curr) => { - // Find if the current item already exists in the accumulator - const existing = acc.find( - (item) => - item['Service_Provider_Name'] === curr['Service_Provider_Name'] && - item.SPID === curr.SPID, - ); - - if (existing) { - // If it exists, push the current "cs" and "c c" values into the arrays - existing.CARNETSTATUS.push(curr.CARNETSTATUS); - existing['Carnet_Count'].push(curr['Carnet_Count']); - } else { - // If it doesn't exist, create a new entry - acc.push({ - Service_Provider_Name: curr['Service_Provider_Name'], - SPID: curr.SPID, - CARNETSTATUS: [curr.CARNETSTATUS], - Carnet_Count: [curr['Carnet_Count']], - }); - } - - return acc; - }, []); - - return rows; - } catch (err) { - if (err instanceof Error) { - return { error: err.message }; - } else { - return { error: 'An unknown error occurred' }; - } - } - finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - console.error('Failed to close connection:', closeErr); - } + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } + + return fres; + } catch (error) { + handleError(error, HomePageService.name) + } finally { + await closeOracleDbConnection(connection, HomePageService.name) } } - // NOTE : this has been moved to carent-application module - - // async SaveCarnetApplication(body: SaveCarnetApplicationDTO) { - // const newBody = { - // p_headerid: null, - // p_holderid: null, - // p_commercialsampleflag: null, - // p_profequipmentflag: null, - // p_exhibitionsfairflag: null, - // p_autoflag: null, - // p_horseflag: null, - // p_authrep: null, - // p_gltable: null, - // p_ussets: null, - // p_countrytable: null, - // p_shiptotype: null, - // p_shipaddrid: null, - // p_formofsecurity: null, - // p_insprotection: null, - // p_ldiprotection: null, - // p_deliverytype: null, - // p_deliverymethod: null, - // p_paymentmethod: null, - // p_custcourierno: null, - // p_refno: null, - // p_notes: null, - // }; - - // const reqBody = JSON.parse(JSON.stringify(body)); - - // function setEmptyStringsToNull(obj) { - // Object.keys(obj).forEach((key) => { - // if (typeof obj[key] === 'object' && obj[key] !== null) { - // setEmptyStringsToNull(obj[key]); - // } else if (obj[key] === '') { - // obj[key] = null; - // } - // }); - // } - - // setEmptyStringsToNull(reqBody); - - // const finalBody = { ...newBody, ...reqBody }; - - // let connection; - // let rows = []; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new Error('No DB Connected'); - // } - - // console.log('here ------------ 1'); - - // // const res = await connection.execute(`SELECT CARNETSYS.GLARRAY(1, 'Description for itemno 1', 2500, 20, 12, 'LBS', 'US') FROM dual`); - - // async function createGLArrayInstance( - // connection, - // itemNo, - // itemDescription, - // itemValue, - // noOfPieces, - // itemWeight, - // itemWeightUOM, - // goodsOriginCountry, - // ) { - // const result = await connection.execute( - // `SELECT CARNETSYS.GLARRAY(:itemNo, :itemDescription, :itemValue, :noOfPieces, :itemWeight, :itemWeightUOM, :goodsOriginCountry) FROM dual`, - // { - // itemNo, - // itemDescription, - // itemValue, - // noOfPieces, - // itemWeight, - // itemWeightUOM, - // goodsOriginCountry, - // }, - // ); - // return result.rows[0][0]; // Access the first row and first column to get the GLARRAY instance - // } - - // async function createCarnetCountryArrayInstance( - // connection, - // visitTransitInd, - // countryCode, - // noOfTimesEntLeave, - // ) { - // const result = await connection.execute( - // `SELECT CARNETSYS.CARNETCOUNTRYARRAY(:visitTransitInd, :countryCode, :noOfTimesEntLeave) FROM dual`, - // { - // visitTransitInd, - // countryCode, - // noOfTimesEntLeave, - // }, - // ); - // return result.rows[0][0]; // Access the first row and first column to get the CARNETCOUNTRYARRAY instance - // } - - // // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name IN ('GLARRAY', 'GLTABLE')`) - - // // let GLARRAY = await connection.getDbObjectClass('CARNETSYS.GLARRAY'); - // const GLTABLE = await connection.getDbObjectClass('CARNETSYS.GLTABLE'); - // // const CARNETCOUNTRYARRAY = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYARRAY'); - // const CARNETCOUNTRYTABLE = await connection.getDbObjectClass( - // 'CARNETSYS.CARNETCOUNTRYTABLE', - // ); - - // // Check if GLTABLE is a constructor - // if (typeof GLTABLE !== 'function') { - // throw new Error('GLTABLE is not a constructor'); - // } - - // if (typeof CARNETCOUNTRYTABLE !== 'function') { - // throw new Error('CARNETCOUNTRYTABLE is not a constructor'); - // } - - // const GLTABLE_ARRAY = finalBody.p_gltable - // ? await Promise.all( - // finalBody.p_gltable.map(async (x: p_gltableDTO) => { - // return await createGLArrayInstance( - // connection, - // x.ItemNo, - // x.ItemDescription, - // x.ItemValue, - // x.Noofpieces, - // x.ItemWeight, - // x.ItemWeightUOM, - // x.GoodsOriginCountry, - // ); - // }), - // ) - // : []; - - // const CARNETCOUNTRYTABLE_ARRAY = finalBody.p_countrytable - // ? await Promise.all( - // finalBody.p_countrytable.map(async (x) => { - // return await createCarnetCountryArrayInstance( - // connection, - // x.VisitTransitInd, - // x.CountryCode, - // x.NoOfTimesEntLeave, - // ); - // }), - // ) - // : []; - - // const GLTABLE_INSTANCE = new GLTABLE(GLTABLE_ARRAY); - // const CARNETCOUNTRYTABLE_INSTANCE = new CARNETCOUNTRYTABLE( - // CARNETCOUNTRYTABLE_ARRAY, - // ); - - // const result = await connection.execute( - // `BEGIN - // CARNETAPPLICATION_PKG.SaveCarnetApplication( - // :P_SPID, - // :p_clientid, - // :p_locationid, - // :P_USERID, - // :p_headerid, - // :p_applicationname, - // :p_holderid, - // :p_commercialsampleflag, - // :p_profequipmentflag, - // :p_exhibitionsfairflag, - // :p_autoflag, - // :p_horseflag, - // :p_authrep, - // :p_gltable, - // :p_ussets, - // :p_countrytable, - // :p_shiptotype, - // :p_shipaddrid, - // :p_formofsecurity, - // :p_insprotection, - // :p_ldiprotection, - // :p_deliverytype, - // :p_deliverymethod, - // :p_paymentmethod, - // :p_custcourierno, - // :p_refno, - // :p_notes, - // :P_CURSOR - // ); - // END;`, - // { - // P_SPID: { - // val: finalBody.P_SPID ? finalBody.P_SPID : null, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // p_clientid: { - // val: finalBody.p_clientid ? finalBody.p_clientid : null, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // p_locationid: { - // val: finalBody.p_locationid ? finalBody.p_locationid : null, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_USERID: { - // val: finalBody.P_USERID ? finalBody.P_USERID : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_headerid: { - // val: finalBody.p_headerid ? finalBody.p_headerid : null, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // p_applicationname: { - // val: finalBody.p_applicationname - // ? finalBody.p_applicationname - // : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_holderid: { - // val: finalBody.p_holderid ? finalBody.p_holderid : null, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // p_commercialsampleflag: { - // val: finalBody.p_commercialsampleflag - // ? finalBody.p_commercialsampleflag - // : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_profequipmentflag: { - // val: finalBody.p_profequipmentflag - // ? finalBody.p_profequipmentflag - // : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_exhibitionsfairflag: { - // val: finalBody.p_exhibitionsfairflag - // ? finalBody.p_exhibitionsfairflag - // : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_autoflag: { - // val: finalBody.p_autoflag ? finalBody.p_autoflag : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_horseflag: { - // val: finalBody.p_horseflag ? finalBody.p_horseflag : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_authrep: { - // val: finalBody.p_authrep ? finalBody.p_authrep : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_gltable: { - // val: GLTABLE_INSTANCE, - // type: oracledb.DB_TYPE_OBJECT, - // }, - // p_ussets: { - // val: finalBody.p_ussets ? finalBody.p_ussets : null, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // p_countrytable: { - // val: CARNETCOUNTRYTABLE_INSTANCE, - // type: oracledb.DB_TYPE_OBJECT, - // }, - // p_shiptotype: { - // val: finalBody.p_shiptotype ? finalBody.p_shiptotype : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_shipaddrid: { - // val: finalBody.p_shipaddrid ? finalBody.p_shipaddrid : null, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // p_formofsecurity: { - // val: finalBody.p_formofsecurity ? finalBody.p_formofsecurity : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_insprotection: { - // val: finalBody.p_insprotection ? finalBody.p_insprotection : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_ldiprotection: { - // val: finalBody.p_ldiprotection ? finalBody.p_ldiprotection : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_deliverytype: { - // val: finalBody.p_deliverytype ? finalBody.p_deliverytype : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_deliverymethod: { - // val: finalBody.p_deliverymethod ? finalBody.p_deliverymethod : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_paymentmethod: { - // val: finalBody.p_paymentmethod ? finalBody.p_paymentmethod : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_custcourierno: { - // val: finalBody.p_custcourierno ? finalBody.p_custcourierno : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_refno: { - // val: finalBody.p_refno ? finalBody.p_refno : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_notes: { - // val: finalBody.p_notes ? finalBody.p_notes : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - // await connection.commit(); - - // 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 Error('No cursor returned from the stored procedure'); - // } - - // return rows; - // } catch (err) { - // if (err instanceof Error) { - // return { error: err.message }; - // } else { - // return { error: 'An unknown error occurred' }; - // } - // } - // finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // console.error('Failed to close connection:', closeErr); - // } - // } - // } - // } - - // NOTE : this has been moved to carent-application module - - // async TransmitApplicationtoProcess(body: TransmitApplicationtoProcessDTO) { - // let connection; - // let rows = []; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new Error('No DB Connected'); - // } - - // const result = await connection.execute( - // `BEGIN - // CARNETAPPLICATION_PKG.TransmitApplicationtoProcess( - // :P_SPID, - // :P_USERID, - // :p_headerid, - // :P_CURSOR - // ); - // END;`, - // { - // P_SPID: { - // val: body.P_SPID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_USERID: { - // val: body.P_USERID, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_headerid: { - // val: body.p_headerid, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - // await connection.commit(); - - // 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 Error('No cursor returned from the stored procedure'); - // } - - // return rows; - - // // return fres - // } catch (err) { - // if (err instanceof Error) { - // return { error: err.message }; - // } else { - // return { error: 'An unknown error occurred' }; - // } - // } - // finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // console.error('Failed to close connection:', closeErr); - // } - // } - // } - // } - async GetCarnetDetailsbyCarnetStatus(body: GetCarnetDetailsbyCarnetStatusDTO) { let connection; - let rows: any = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result = await connection.execute( `BEGIN CARNETCONTROLCENTER_PKG.GetCarnetDetails(:P_SPID,:P_USERID,:P_CARNETSTATUS,:P_CURSOR); END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CARNETSTATUS: { - val: body.P_CARNETSTATUS, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + P_CARNETSTATUS: { val: body.P_CARNETSTATUS, type: oracledb.DB_TYPE_NVARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, + 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 Error('No cursor returned from the stored procedure'); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - return rows; - } catch (err) { - if (err instanceof Error) { - return { error: err.message }; - } else { - return { error: 'An unknown error occurred' }; - } - } - finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - console.error('Failed to close connection:', closeErr); - } + const fres: any = await fetchCursor(outBinds.P_CURSOR, HomePageService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } + + return fres; + } catch (error) { + handleError(error, HomePageService.name) + } finally { + await closeOracleDbConnection(connection, HomePageService.name) } } } diff --git a/src/oracle/manage-fee/manage-fee.controller.ts b/src/oracle/manage-fee/manage-fee.controller.ts index 2861cd1..60092a2 100644 --- a/src/oracle/manage-fee/manage-fee.controller.ts +++ b/src/oracle/manage-fee/manage-fee.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Patch, Post, Query } from '@nestjs/common'; +import { Body, Controller, Get, Param, Patch, Post, Query } from '@nestjs/common'; import { ManageFeeService } from './manage-fee.service'; import { ApiTags } from '@nestjs/swagger'; @@ -13,44 +13,44 @@ export class ManageFeeController { constructor(private readonly manageFeeService: ManageFeeService) { } @ApiTags('Manage Fee - Oracle') - @Get('/GetBasicFeeRates') - GetBasicFeeRates(@Query() body: GetFeeGeneralDTO) { + @Get('/GetBasicFeeRates/:P_SPID/:P_ACTIVE_INACTIVE') + GetBasicFeeRates(@Param() body: GetFeeGeneralDTO) { return this.manageFeeService.GETBASICFEERATES(body); } @ApiTags('Manage Fee - Oracle') - @Get('/GetBondRates') - GetBondRates(@Query() body: GetFeeGeneralDTO) { + @Get('/GetBondRates/:P_SPID/:P_ACTIVE_INACTIVE') + GetBondRates(@Param() body: GetFeeGeneralDTO) { return this.manageFeeService.GETBONDRATES(body); } @ApiTags('Manage Fee - Oracle') - @Get('/GetCargoRates') - GetCargoRates(@Query() body: GetFeeGeneralDTO) { + @Get('/GetCargoRates/:P_SPID/:P_ACTIVE_INACTIVE') + GetCargoRates(@Param() body: GetFeeGeneralDTO) { return this.manageFeeService.GETCARGORATES(body); } @ApiTags('Manage Fee - Oracle') - @Get('/GetCfFeeRates') - GetCfFeeRates(@Query() body: GetFeeGeneralDTO) { + @Get('/GetCfFeeRates/:P_SPID/:P_ACTIVE_INACTIVE') + GetCfFeeRates(@Param() body: GetFeeGeneralDTO) { return this.manageFeeService.GETCFFEERATES(body); } @ApiTags('Manage Fee - Oracle') - @Get('/GetCsFeeRates') - GetCsFeeRates(@Query() body: GetFeeGeneralDTO) { + @Get('/GetCsFeeRates/:P_SPID/:P_ACTIVE_INACTIVE') + GetCsFeeRates(@Param() body: GetFeeGeneralDTO) { return this.manageFeeService.GETCSFEERATES(body); } @ApiTags('Manage Fee - Oracle') - @Get('/GetEfFeeRates') - GetEfFeeRates(@Query() body: GetFeeGeneralDTO) { + @Get('/GetEfFeeRates/:P_SPID/:P_ACTIVE_INACTIVE') + GetEfFeeRates(@Param() body: GetFeeGeneralDTO) { return this.manageFeeService.GETEFFEERATES(body); } @ApiTags('Manage Fee - Oracle') - @Get('/GetFeeComm') - GetFeeComm(@Query() body: GetFeeGeneralDTO) { + @Get('/GetFeeComm/:P_SPID/:P_ACTIVE_INACTIVE') + GetFeeComm(@Param() body: GetFeeGeneralDTO) { return this.manageFeeService.GETFEECOMM(body); } diff --git a/src/oracle/manage-fee/manage-fee.service.ts b/src/oracle/manage-fee/manage-fee.service.ts index 250a515..82a43e3 100644 --- a/src/oracle/manage-fee/manage-fee.service.ts +++ b/src/oracle/manage-fee/manage-fee.service.ts @@ -5,7 +5,7 @@ import { OracleDBService } from 'src/db/db.service'; import { BadRequestException } from 'src/exceptions/badRequest.exception'; import { InternalServerException } from 'src/exceptions/internalServerError.exception'; -import { closeOracleDbConnection, handleError } from 'src/utils/helper'; +import { closeOracleDbConnection, fetchCursor, handleError } from 'src/utils/helper'; import { CreateBasicFeeDTO, CreateBondRateDTO, CreateCargoRateDTO, CreateCfFeeDTO, CreateCsFeeDTO, @@ -23,56 +23,36 @@ export class ManageFeeService { async GETBASICFEERATES(body: GetFeeGeneralDTO) { 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.GETBASICFEERATES(:P_SPID, :P_ACTIVE_INACTIVE, :p_cursor); + MANAGEFEE_SETUP_PKG.GETBASICFEERATES(: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, - }, + 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 }, + { outFormat: oracledb.OUT_FORMAT_OBJECT } ); - if (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 { - this.logger.error(`Invalid response from database procedure`); - throw new BadRequestException(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - if (rows.length > 0 && rows[0].ERRORMESG) { - this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`); - throw new BadRequestException(rows[0].ERRORMESG); + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageFeeService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return rows; + return fres; } catch (error) { handleError(error, ManageFeeService.name) @@ -85,56 +65,26 @@ export class ManageFeeService { 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.CREATEBASICFEE( - :P_SPID, - :P_STARTCARNETVALUE, - :P_ENDCARNETVALUE, - :P_EFFDATE, - :P_FEES, - :P_USERID, - :P_CURSOR); + `BEGIN + MANAGEFEE_SETUP_PKG.CREATEBASICFEE( + :P_SPID, :P_STARTCARNETVALUE, :P_ENDCARNETVALUE, :P_EFFDATE, + :P_FEES, :P_USERID, :P_CURSOR + ); END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_STARTCARNETVALUE: { - val: body.P_STARTNUMBER, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ENDCARNETVALUE: { - val: body.P_ENDNUMBER, - type: oracledb.DB_TYPE_NUMBER, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_FEES: { - val: body.P_FEES, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR, - }, - - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_STARTCARNETVALUE: { val: body.P_STARTNUMBER, type: oracledb.DB_TYPE_NUMBER }, + P_ENDCARNETVALUE: { val: body.P_ENDNUMBER, type: oracledb.DB_TYPE_NUMBER }, + P_EFFDATE: { val: body.P_EFFDATE, type: oracledb.DB_TYPE_VARCHAR }, + P_FEES: { val: body.P_FEES, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_VARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -157,45 +107,24 @@ export class ManageFeeService { 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); + :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, - }, + 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, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -218,60 +147,37 @@ export class ManageFeeService { async GETBONDRATES(body: GetFeeGeneralDTO) { 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); + 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, - }, + 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, - }, + 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() + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - console.warn(rows); + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageFeeService.name); - - if (rows.length > 0 && rows[0].ERRORMESG) { - console.log(rows[0].ERRORMESG); - throw new BadRequestException(rows[0].ERRORMESG) + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return rows; + return fres; } catch (error) { handleError(error, ManageFeeService.name) } finally { @@ -283,65 +189,29 @@ export class ManageFeeService { 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.CREATEBONDRATE( - :P_SPID, - :P_HOLDERTYPE, - :P_USCIBMEMBERFLAG, - :P_SPCLCOMMODITY, - :P_SPCLCOUNTRY, - :P_EFFDATE, - :P_RATE, - :P_USERID, - :P_CURSOR); + `BEGIN + MANAGEFEE_SETUP_PKG.CREATEBONDRATE( + :P_SPID, :P_HOLDERTYPE, :P_USCIBMEMBERFLAG, :P_SPCLCOMMODITY, + :P_SPCLCOUNTRY, :P_EFFDATE, :P_RATE, :P_USERID, + :P_CURSOR + ); END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_HOLDERTYPE: { - val: body.P_HOLDERTYPE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_USCIBMEMBERFLAG: { - val: body.P_USCIBMEMBERFLAG, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_SPCLCOMMODITY: { - val: body.P_SPCLCOMMODITY, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_SPCLCOUNTRY: { - val: body.P_SPCLCOUNTRY, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_HOLDERTYPE: { val: body.P_HOLDERTYPE, type: oracledb.DB_TYPE_VARCHAR }, + P_USCIBMEMBERFLAG: { val: body.P_USCIBMEMBERFLAG, type: oracledb.DB_TYPE_VARCHAR }, + P_SPCLCOMMODITY: { val: body.P_SPCLCOMMODITY, type: oracledb.DB_TYPE_VARCHAR }, + P_SPCLCOUNTRY: { val: body.P_SPCLCOUNTRY, type: oracledb.DB_TYPE_VARCHAR }, + P_EFFDATE: { val: body.P_EFFDATE, type: oracledb.DB_TYPE_VARCHAR }, + P_RATE: { val: body.P_RATE, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_VARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -364,45 +234,24 @@ export class ManageFeeService { 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); + :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, - }, + 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, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -423,79 +272,43 @@ export class ManageFeeService { // cargo rate - async GETCARGORATES(body: GetFeeGeneralDTO): Promise { + async GETCARGORATES(body: GetFeeGeneralDTO) { 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); + 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, - }, + 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, - }, + 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(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - if (rows.length > 0 && rows[0].ERRORMESG) { - this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`); - throw new BadRequestException(rows[0].ERRORMESG); + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageFeeService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return rows; + return fres; } 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(); + handleError(error, ManageFeeService.name) } finally { - // Ensure connection is closed - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } + await closeOracleDbConnection(connection, ManageFeeService.name) } } @@ -504,60 +317,27 @@ export class ManageFeeService { 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.CREATECARGORATE( - :P_SPID, - :P_CARNETTYPE, - :P_STARTSETS, - :P_ENDSETS, - :P_EFFDATE, - :P_RATE, - :P_USERID, - :P_CURSOR); + `BEGIN + MANAGEFEE_SETUP_PKG.CREATECARGORATE( + :P_SPID, :P_CARNETTYPE, :P_STARTSETS, :P_ENDSETS, + :P_EFFDATE, :P_RATE, :P_USERID, :P_CURSOR + ); END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CARNETTYPE: { - val: body.P_CARNETTYPE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_STARTSETS: { - val: body.P_STARTSETS, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ENDSETS: { - val: body.P_ENDSETS, - type: oracledb.DB_TYPE_NUMBER, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CARNETTYPE: { val: body.P_CARNETTYPE, type: oracledb.DB_TYPE_VARCHAR }, + P_STARTSETS: { val: body.P_STARTSETS, type: oracledb.DB_TYPE_NUMBER }, + P_ENDSETS: { val: body.P_ENDSETS, type: oracledb.DB_TYPE_NUMBER }, + P_EFFDATE: { val: body.P_EFFDATE, type: oracledb.DB_TYPE_VARCHAR }, + P_RATE: { val: body.P_RATE, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_VARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -580,45 +360,24 @@ export class ManageFeeService { 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); + :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, - }, + 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, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -641,57 +400,37 @@ export class ManageFeeService { async GETCFFEERATES(body: GetFeeGeneralDTO) { 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); + 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, - }, + 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, - }, + 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(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - if (rows.length > 0 && rows[0].ERRORMESG) { - this.logger.warn(`error from DB: ${rows[0].ERRORMESG}`); - throw new BadRequestException(rows[0].ERRORMESG); + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageFeeService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return rows; + return fres; } catch (error) { handleError(error, ManageFeeService.name) } finally { @@ -703,65 +442,29 @@ export class ManageFeeService { 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.CREATECFFEE( - :P_SPID, - :P_STARTSETS, - :P_ENDSETS, - :P_EFFDATE, - :P_CUSTOMERTYPE, - :P_CARNETTYPE, - :P_RATE, - :P_USERID, - :P_CURSOR); + `BEGIN + MANAGEFEE_SETUP_PKG.CREATECFFEE( + :P_SPID, :P_STARTSETS, :P_ENDSETS, :P_EFFDATE, + :P_CUSTOMERTYPE, :P_CARNETTYPE, :P_RATE, :P_USERID, + :P_CURSOR + ); END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_STARTSETS: { - val: body.P_STARTSETS, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ENDSETS: { - val: body.P_ENDSETS, - type: oracledb.DB_TYPE_NUMBER, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_CUSTOMERTYPE: { - val: body.P_CUSTOMERTYPE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_CARNETTYPE: { - val: body.P_CARNETTYPE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_STARTSETS: { val: body.P_STARTSETS, type: oracledb.DB_TYPE_NUMBER }, + P_ENDSETS: { val: body.P_ENDSETS, type: oracledb.DB_TYPE_NUMBER }, + P_EFFDATE: { val: body.P_EFFDATE, type: oracledb.DB_TYPE_VARCHAR }, + P_CUSTOMERTYPE: { val: body.P_CUSTOMERTYPE, type: oracledb.DB_TYPE_VARCHAR }, + P_CARNETTYPE: { val: body.P_CARNETTYPE, type: oracledb.DB_TYPE_VARCHAR }, + P_RATE: { val: body.P_RATE, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_VARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -784,45 +487,24 @@ export class ManageFeeService { 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); + :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, - }, + 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, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -846,57 +528,37 @@ export class ManageFeeService { async GETCSFEERATES(body: GetFeeGeneralDTO) { 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); + 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, - }, + 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, - }, + 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(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - if (rows.length > 0 && rows[0].ERRORMESG) { - console.log(rows[0].ERRORMESG); - throw new BadRequestException(rows[0].ERRORMESG) + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageFeeService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return rows; + return fres; } catch (error) { handleError(error, ManageFeeService.name) } finally { @@ -908,55 +570,26 @@ export class ManageFeeService { 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.CREATECSFEE( - :P_SPID, - :P_CUSTOMERTYPE, - :P_CARNETTYPE, - :P_EFFDATE, - :P_RATE, - :P_USERID, - :P_CURSOR); + `BEGIN + MANAGEFEE_SETUP_PKG.CREATECSFEE( + :P_SPID, :P_CUSTOMERTYPE, :P_CARNETTYPE, :P_EFFDATE, + :P_RATE, :P_USERID, :P_CURSOR + ); END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CUSTOMERTYPE: { - val: body.P_CUSTOMERTYPE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_CARNETTYPE: { - val: body.P_CARNETTYPE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_RATE: { - val: body.P_RATE, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CUSTOMERTYPE: { val: body.P_CUSTOMERTYPE, type: oracledb.DB_TYPE_VARCHAR }, + P_CARNETTYPE: { val: body.P_CARNETTYPE, type: oracledb.DB_TYPE_VARCHAR }, + P_EFFDATE: { val: body.P_EFFDATE, type: oracledb.DB_TYPE_VARCHAR }, + P_RATE: { val: body.P_RATE, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_VARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -979,45 +612,24 @@ export class ManageFeeService { 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); + :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, - }, + 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, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -1040,57 +652,37 @@ export class ManageFeeService { async GETEFFEERATES(body: GetFeeGeneralDTO) { 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); + 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, - }, + 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, - }, + 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(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - if (rows.length > 0 && rows[0].ERRORMESG) { - console.log(rows[0].ERRORMESG); - throw new BadRequestException(rows[0].ERRORMESG) + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageFeeService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return rows; + return fres; } catch (error) { handleError(error, ManageFeeService.name) } finally { @@ -1102,71 +694,30 @@ export class ManageFeeService { 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.CREATEEFFEE( - :P_SPID, - :P_CUSTOMERTYPE, - :P_DELIVERYTYPE, - :P_STARTTIME, - :P_ENDTIME, - :P_TIMEZONE, - :P_EFFDATE, - :P_FEES, - :P_USERID, - :P_CURSOR - ); + `BEGIN + MANAGEFEE_SETUP_PKG.CREATEEFFEE( + :P_SPID, :P_CUSTOMERTYPE, :P_DELIVERYTYPE, :P_STARTTIME, + :P_ENDTIME, :P_TIMEZONE, :P_EFFDATE, :P_FEES, + :P_USERID, :P_CURSOR + ); END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CUSTOMERTYPE: { - val: body.P_CUSTOMERTYPE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_DELIVERYTYPE: { - val: body.P_DELIVERYTYPE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_STARTTIME: { - val: body.P_STARTTIME, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ENDTIME: { - val: body.P_ENDTIME, - type: oracledb.DB_TYPE_NUMBER, - }, - P_TIMEZONE: { - val: body.P_TIMEZONE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_EFFDATE: { - val: body.P_EFFDATE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_FEES: { - val: body.P_FEES, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CUSTOMERTYPE: { val: body.P_CUSTOMERTYPE, type: oracledb.DB_TYPE_VARCHAR }, + P_DELIVERYTYPE: { val: body.P_DELIVERYTYPE, type: oracledb.DB_TYPE_VARCHAR }, + P_STARTTIME: { val: body.P_STARTTIME, type: oracledb.DB_TYPE_NUMBER }, + P_ENDTIME: { val: body.P_ENDTIME, type: oracledb.DB_TYPE_NUMBER }, + P_TIMEZONE: { val: body.P_TIMEZONE, type: oracledb.DB_TYPE_VARCHAR }, + P_EFFDATE: { val: body.P_EFFDATE, type: oracledb.DB_TYPE_VARCHAR }, + P_FEES: { val: body.P_FEES, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_VARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { - outFormat: oracledb.OUT_FORMAT_OBJECT, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -1189,45 +740,24 @@ export class ManageFeeService { 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); + :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, - }, + 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, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -1250,57 +780,37 @@ export class ManageFeeService { async GETFEECOMM(body: GetFeeGeneralDTO) { 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); + 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, - }, + 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, - }, + 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(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - if (rows.length > 0 && rows[0].ERRORMESG) { - console.log(rows[0].ERRORMESG); - throw new BadRequestException(rows[0].ERRORMESG) + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageFeeService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return rows; + return fres; } catch (error) { handleError(error, ManageFeeService.name) } finally { @@ -1312,50 +822,25 @@ export class ManageFeeService { 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.CREATEFEECOMM( - :P_SPID, - :P_PARAMID, - :P_COMMRATE, - :P_EFFDATE, - :P_USERID, - :P_CURSOR); - END;`, + MANAGEFEE_SETUP_PKG.CREATEFEECOMM( + :P_SPID, :P_PARAMID, :P_COMMRATE, :P_EFFDATE, + :P_USERID, :P_CURSOR + ); + END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_PARAMID: { - val: body.P_PARAMID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_COMMRATE: { - val: body.P_COMMRATE, - 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, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_PARAMID: { val: body.P_PARAMID, type: oracledb.DB_TYPE_NUMBER }, + P_COMMRATE: { val: body.P_COMMRATE, 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, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); @@ -1378,45 +863,24 @@ export class ManageFeeService { 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.UPDATEFEECOMM( - :P_FEECOMMID, - :P_RATE, - :P_EFFDATE, - :P_USERID, - :P_CURSOR); + :P_FEECOMMID, :P_RATE, :P_EFFDATE, :P_USERID, + :P_CURSOR + ); END;`, { - P_FEECOMMID: { - val: body.P_FEECOMMID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_RATE: { - val: Number(body.P_RATE) | 0, - 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, - }, + P_FEECOMMID: { val: body.P_FEECOMMID, type: oracledb.DB_TYPE_NUMBER }, + P_RATE: { val: Number(body.P_RATE) | 0, 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, - }, + outFormat: oracledb.OUT_FORMAT_OBJECT + } ); await connection.commit(); diff --git a/src/oracle/manage-holders/manage-holders.controller.ts b/src/oracle/manage-holders/manage-holders.controller.ts index 2beb563..79d3da5 100644 --- a/src/oracle/manage-holders/manage-holders.controller.ts +++ b/src/oracle/manage-holders/manage-holders.controller.ts @@ -43,95 +43,37 @@ export class ManageHoldersController { @ApiTags('Manage Holders - Oracle') @Get('/GetHolderRecord/:P_SPID/:P_HOLDERID') - GetHolderMaster( - @Param('P_SPID', ParseIntPipe) P_SPID: number, - @Param('P_HOLDERID', ParseIntPipe) P_HOLDERID: number, - ) { - const reqParams: GetHolderDTO = { P_SPID, P_HOLDERID }; - - return this.manageHoldersService.GetHolderRecord(reqParams); + GetHolderMaster(@Param() body: GetHolderDTO) { + return this.manageHoldersService.GetHolderRecord(body); } @ApiTags('Manage Holders - Oracle') @Get('/GetHolderContacts/:P_SPID/:P_HOLDERID') - GetHolderContacts( - @Param('P_SPID', ParseIntPipe) P_SPID: number, - @Param('P_HOLDERID', ParseIntPipe) P_HOLDERID: number, - ) { - const reqParams: GetHolderDTO = { P_SPID, P_HOLDERID }; - - return this.manageHoldersService.GetHolderContacts(reqParams); + GetHolderContacts(@Param() body: GetHolderDTO) { + return this.manageHoldersService.GetHolderContacts(body); } @ApiTags('Manage Holders - Oracle') @Patch('/InactivateHolder/:P_SPID/:P_HOLDERID/:P_USERID') - InactivateHolder( - @Param('P_SPID', ParseIntPipe) P_SPID: number, - @Param('P_HOLDERID', ParseIntPipe) P_HOLDERID: number, - @Param('P_USERID') P_USERID: string - ) { - if (!P_USERID) { - throw new BadRequestException("Bad Request"); - } - const reqParams: HolderActivateOrInactivateDTO = { P_SPID, P_HOLDERID, P_USERID }; - - return this.manageHoldersService.InactivateHolder(reqParams); + InactivateHolder(@Param() body: HolderActivateOrInactivateDTO) { + return this.manageHoldersService.InactivateHolder(body); } @ApiTags('Manage Holders - Oracle') @Patch('/ReactivateHolder/:P_SPID/:P_HOLDERID/:P_USERID') - ReactivateHolder( - @Param('P_SPID', ParseIntPipe) P_SPID: number, - @Param('P_HOLDERID', ParseIntPipe) P_HOLDERID: number, - @Param('P_USERID') P_USERID: string - ) { - if (!P_USERID) { - throw new BadRequestException("Bad Request"); - } - - const reqParams: HolderActivateOrInactivateDTO = { P_SPID, P_HOLDERID, P_USERID }; - - return this.manageHoldersService.ReactivateHolder(reqParams); + ReactivateHolder(@Param() body: HolderActivateOrInactivateDTO) { + return this.manageHoldersService.ReactivateHolder(body); } @ApiTags('Manage Holders - Oracle') @Patch('/InactivateHolderContact/:P_SPID/:P_HOLDERCONTACTID/:P_USERID') - InactivateHolderContact( - @Param('P_SPID', ParseIntPipe) P_SPID: number, - @Param('P_HOLDERCONTACTID', ParseIntPipe) P_HOLDERCONTACTID: number, - @Param('P_USERID') P_USERID: string - ) { - - if (!P_USERID) { - throw new BadRequestException("Bad Request"); - } - - const reqParams: HolderContactActivateOrInactivateDTO = { - P_SPID, - P_HOLDERCONTACTID, - P_USERID - }; - - return this.manageHoldersService.InactivateHolderContact(reqParams); + InactivateHolderContact(@Param() body: HolderContactActivateOrInactivateDTO) { + return this.manageHoldersService.InactivateHolderContact(body); } @ApiTags('Manage Holders - Oracle') @Patch('/ReactivateHolderContact/:P_SPID/:P_HOLDERCONTACTID/:P_USERID') - ReactivateHolderContact( - @Param('P_SPID', ParseIntPipe) P_SPID: number, - @Param('P_HOLDERCONTACTID', ParseIntPipe) P_HOLDERCONTACTID: number, - @Param('P_USERID') P_USERID: string - ) { - if (!P_USERID) { - throw new BadRequestException("Bad Request"); - } - - const reqParams: HolderContactActivateOrInactivateDTO = { - P_SPID, - P_HOLDERCONTACTID, - P_USERID - }; - - return this.manageHoldersService.ReactivateHolderContact(reqParams); + ReactivateHolderContact(@Param() body: HolderContactActivateOrInactivateDTO) { + return this.manageHoldersService.ReactivateHolderContact(body); } } diff --git a/src/oracle/manage-holders/manage-holders.service.ts b/src/oracle/manage-holders/manage-holders.service.ts index ef95b28..afed486 100644 --- a/src/oracle/manage-holders/manage-holders.service.ts +++ b/src/oracle/manage-holders/manage-holders.service.ts @@ -3,13 +3,14 @@ import { OracleDBService } from 'src/db/db.service'; import * as oracledb from 'oracledb'; import { Connection, Result } from 'oracledb'; import { InternalServerException } from 'src/exceptions/internalServerError.exception'; -import { closeOracleDbConnection, fetchCursor, handleError } from 'src/utils/helper'; +import { closeOracleDbConnection, fetchCursor, handleError, setEmptyStringsToNull } from 'src/utils/helper'; import { - CONTACTSTABLE_ROW_DTO, CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO, + CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO, HolderContactActivateOrInactivateDTO, UpdateHolderContactDTO, UpdateHolderDTO } from 'src/dto/property.dto'; import { OracleService } from '../oracle.service'; +import { BadRequestException } from 'src/exceptions/badRequest.exception'; @Injectable() export class ManageHoldersService { @@ -20,283 +21,6 @@ export class ManageHoldersService { private readonly oracleService: OracleService ) { } - // CreateHoldersX = async (body: CreateHoldersDTO) => { - // const newBody = { - // p_spid: null, - // p_clientlocationid: null, - // p_holderno: null, - // p_holdertype: null, - // p_uscibmemberflag: null, - // p_govagencyflag: null, - // p_holdername: null, - // p_namequalifier: null, - // p_addlname: null, - // p_address1: null, - // p_address2: null, - // p_city: null, - // p_state: null, - // p_zip: null, - // p_country: null, - // p_userid: null, - // p_contactstable: null, - // }; - - // const reqBody = JSON.parse(JSON.stringify(body)); - - // function setEmptyStringsToNull(obj) { - // Object.keys(obj).forEach((key) => { - // if (typeof obj[key] === 'object' && obj[key] !== null) { - // setEmptyStringsToNull(obj[key]); - // } else if (obj[key] === '') { - // obj[key] = null; - // } - // }); - // } - - // setEmptyStringsToNull(reqBody); - - // const finalBody: CreateHoldersDTO = { ...newBody, ...reqBody }; - - // let connection: Connection | undefined = undefined; - // let p_holdercursor_rows = []; - // let p_holdercontactcursor_rows = []; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CONTACT%'`); - - // // return { res:res.rows }; - - // // const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY'); - // const CONTACTSTABLE = await connection.getDbObjectClass( - // 'CARNETSYS.CONTACTSTABLE', - // ); - - // // Check if GLTABLE is a constructor - // if (typeof CONTACTSTABLE !== 'function') { - // throw new Error('CONTACTSTABLE is not a constructor'); - // } - - // async function CREATECONTACTSTABLE_INSTANCE( - // connection, - // FirstName, - // LastName, - // MiddleInitial, - // Title, - // EmailAddress, - // PhoneNo, - // MobileNo, - // FaxNo, - // ) { - // const result: Result = await connection.execute( - // `SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`, - // { - // FirstName, - // LastName, - // MiddleInitial, - // Title, - // EmailAddress, - // PhoneNo, - // MobileNo, - // FaxNo, - // }, - // ); - // return result.rows?.[0]?.[0] ?? []; - // } - - // const CONTACTSARRAY = finalBody.P_CONTACTSTABLE - // ? await Promise.all( - // finalBody.p_contactstable.map(async (x: p_contactstableDTO) => { - // return await CREATECONTACTSTABLE_INSTANCE( - // connection, - // x.FirstName, - // x.LastName, - // x.MiddleInitial, - // x.Title, - // x.EmailAddress, - // x.PhoneNo, - // x.MobileNo, - // x.FaxNo, - // ); - // }), - // ) - // : []; - - // // Create an instance of GLTABLE - // const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); - - // const result: Result = 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;`, - // { - // p_spid: { - // val: finalBody.p_spid ? finalBody.p_spid : null, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // p_clientlocationid: { - // val: finalBody.p_clientlocationid - // ? finalBody.p_clientlocationid - // : null, - // type: oracledb.DB_TYPE_NUMBER, - // }, - - // p_holderno: { - // val: finalBody.p_holderno ? finalBody.p_holderno : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_holdertype: { - // val: finalBody.p_holdertype ? finalBody.p_holdertype : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_uscibmemberflag: { - // val: finalBody.p_uscibmemberflag - // ? finalBody.p_uscibmemberflag - // : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_govagencyflag: { - // val: finalBody.p_govagencyflag ? finalBody.p_govagencyflag : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_holdername: { - // val: finalBody.p_holdername ? finalBody.p_holdername : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_namequalifier: { - // val: finalBody.p_namequalifier ? finalBody.p_namequalifier : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_addlname: { - // val: finalBody.p_addlname ? finalBody.p_addlname : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_address1: { - // val: finalBody.p_address1 ? finalBody.p_address1 : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_address2: { - // val: finalBody.p_address2 ? finalBody.p_address2 : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_city: { - // val: finalBody.p_city ? finalBody.p_city : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_state: { - // val: finalBody.p_state ? finalBody.p_state : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_zip: { - // val: finalBody.p_zip ? finalBody.p_zip : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_country: { - // val: finalBody.p_country ? finalBody.p_country : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_userid: { - // val: finalBody.p_userid ? finalBody.p_userid : null, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_contactstable: { - // val: CONTACTSTABLE_INSTANCE, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // p_holdercursor: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // p_holdercontactcursor: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - - // await connection.commit(); - - // // let fres = await result.outBinds.P_cursor.getRows(); - - // if (result.outBinds && result.outBinds.p_holdercursor) { - // const cursor = result.outBinds.p_holdercursor; - // let rowsBatch; - - // do { - // rowsBatch = await cursor.getRows(100); - // p_holdercursor_rows = p_holdercursor_rows.concat(rowsBatch); - // } while (rowsBatch.length > 0); - - // await cursor.close(); - // } else { - // throw new BadRequestException(); - // } - - // if (result.outBinds && result.outBinds.p_holdercontactcursor) { - // const cursor = result.outBinds.p_holdercontactcursor; - // let rowsBatch; - - // do { - // rowsBatch = await cursor.getRows(100); - // p_holdercontactcursor_rows = - // p_holdercontactcursor_rows.concat(rowsBatch); - // } while (rowsBatch.length > 0); - - // await cursor.close(); - // } else { - // throw new BadRequestException(); - // } - - // return { - // p_holdercursor: p_holdercursor_rows, - // p_holdercontactcursor: p_holdercontactcursor_rows, - // }; - - // // return fres - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('CreateHolders 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 CreateHolders(body: CreateHoldersDTO) { const newBody = { P_SPID: null, @@ -320,16 +44,6 @@ export class ManageHoldersService { const reqBody = JSON.parse(JSON.stringify(body)); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach((key) => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === '') { - obj[key] = null; - } - }); - } - setEmptyStringsToNull(reqBody); const finalBody: CreateHoldersDTO = { ...newBody, ...reqBody }; @@ -369,7 +83,7 @@ export class ManageHoldersService { P_ZIP: { val: finalBody.P_ZIP, type: oracledb.DB_TYPE_NVARCHAR }, P_COUNTRY: { val: finalBody.P_COUNTRY, type: oracledb.DB_TYPE_NVARCHAR }, P_USERID: { val: finalBody.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, - P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: 'CARNETSYS.CONTACTSTABLE' }, + P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, P_HOLDERCURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, P_HOLDERCONTACTCURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, @@ -409,147 +123,65 @@ export class ManageHoldersService { UpdateHolder = async (body: UpdateHolderDTO) => { const newBody = { - p_holderid: null, - p_spid: null, - p_locationid: null, - p_holderno: null, - p_holdertype: null, - p_uscibmemberflag: null, - p_govagencyflag: null, - p_holdername: null, - p_namequalifier: null, - p_addlname: null, - p_address1: null, - p_address2: null, - p_city: null, - p_state: null, - p_zip: null, - p_country: null, - p_userid: null, + P_HOLDERID: null, + P_SPID: null, + P_LOCATIONID: null, + P_HOLDerno: null, + P_HOLDERTYPE: null, + P_USCIBMEMBERFLAG: null, + P_GOVAGENCYFLAG: null, + P_HOLDERNAME: null, + P_NAMEQUALIFIER: null, + P_ADDLNAME: null, + P_ADDRESS1: null, + P_ADDRESS2: null, + P_CITY: null, + P_STATE: null, + P_ZIP: null, + P_COUNTRY: null, + P_USERID: null, }; const reqBody = JSON.parse(JSON.stringify(body)); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach((key) => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === '') { - obj[key] = null; - } - }); - } - setEmptyStringsToNull(reqBody); - const finalBody = { ...newBody, ...reqBody }; + const finalBody: UpdateHolderDTO = { ...newBody, ...reqBody }; + + let connection; - let connection: Connection | undefined = undefined; - let P_cursor_rows = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } - const result: Result = await connection.execute( - `BEGIN - MANAGEHOLDER_PKG.UpdateHolders( - :p_holderid, - :p_spid, - :p_locationid, - :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_cursor - ); - END;`, + const result = await connection.execute( + `BEGIN + MANAGEHOLDER_PKG.UPDATEHOLDERS( + :P_HOLDERID, :P_SPID, :P_LOCATIONID, :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_CURSOR + ); + END;`, { - p_holderid: { - val: finalBody.p_holderid ? finalBody.p_holderid : null, - type: oracledb.DB_TYPE_NUMBER, - }, - p_spid: { - val: finalBody.p_spid ? finalBody.p_spid : null, - type: oracledb.DB_TYPE_NUMBER, - }, - p_locationid: { - val: finalBody.p_locationid ? finalBody.p_locationid : null, - type: oracledb.DB_TYPE_NUMBER, - }, - p_holderno: { - val: finalBody.p_holderno ? finalBody.p_holderno : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_holdertype: { - val: finalBody.p_holdertype ? finalBody.p_holdertype : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_uscibmemberflag: { - val: finalBody.p_uscibmemberflag - ? finalBody.p_uscibmemberflag - : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_govagencyflag: { - val: finalBody.p_govagencyflag ? finalBody.p_govagencyflag : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_holdername: { - val: finalBody.p_holdername ? finalBody.p_holdername : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_namequalifier: { - val: finalBody.p_namequalifier ? finalBody.p_namequalifier : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_addlname: { - val: finalBody.p_addlname ? finalBody.p_addlname : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_address1: { - val: finalBody.p_address1 ? finalBody.p_address1 : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_address2: { - val: finalBody.p_address2 ? finalBody.p_address2 : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_city: { - val: finalBody.p_city ? finalBody.p_city : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_state: { - val: finalBody.p_state ? finalBody.p_state : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_zip: { - val: finalBody.p_zip ? finalBody.p_zip : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_country: { - val: finalBody.p_country ? finalBody.p_country : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_userid: { - val: finalBody.p_userid ? finalBody.p_userid : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_cursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_HOLDERID: { VAL: finalBody.P_HOLDERID, TYPE: oracledb.DB_TYPE_NUMBER }, + P_SPID: { VAL: finalBody.P_SPID, TYPE: oracledb.DB_TYPE_NUMBER }, + P_LOCATIONID: { VAL: finalBody.P_LOCATIONID, TYPE: oracledb.DB_TYPE_NUMBER }, + P_HOLDERNO: { VAL: finalBody.P_HOLDERNO, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_HOLDERTYPE: { VAL: finalBody.P_HOLDERTYPE, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_USCIBMEMBERFLAG: { VAL: finalBody.P_USCIBMEMBERFLAG, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_GOVAGENCYFLAG: { VAL: finalBody.P_GOVAGENCYFLAG, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_HOLDERNAME: { VAL: finalBody.P_HOLDERNAME, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_NAMEQUALIFIER: { VAL: finalBody.P_NAMEQUALIFIER, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_ADDLNAME: { VAL: finalBody.P_ADDLNAME, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_ADDRESS1: { VAL: finalBody.P_ADDRESS1, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_ADDRESS2: { VAL: finalBody.P_ADDRESS2, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_CITY: { VAL: finalBody.P_CITY, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_STATE: { VAL: finalBody.P_STATE, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_ZIP: { VAL: finalBody.P_ZIP, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_COUNTRY: { VAL: finalBody.P_COUNTRY, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_USERID: { VAL: finalBody.P_USERID, TYPE: oracledb.DB_TYPE_NVARCHAR }, + P_CURSOR: { TYPE: oracledb.CURSOR, DIR: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT, @@ -557,23 +189,21 @@ export class ManageHoldersService { ); await connection.commit(); - // let fres = await result.outBinds.P_cursor.getRows(); - - if (result.outBinds && result.outBinds.P_cursor) { - const cursor = result.outBinds.P_cursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - P_cursor_rows = P_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - return { P_cursor: P_cursor_rows }; + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + + return { P_cursor: fres }; // return fres } catch (error) { @@ -582,167 +212,97 @@ export class ManageHoldersService { await closeOracleDbConnection(connection, ManageHoldersService.name) } }; + GetHolderRecord = async (body: GetHolderDTO) => { - let connection: Connection | undefined = undefined; - let P_CURSOR_rows = []; + let connection; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result: Result = await connection.execute( `BEGIN MANAGEHOLDER_PKG.GetHolderMaster( - :P_SPID, - :P_HOLDERID, - :P_CURSOR + :P_SPID, :P_HOLDERID, :P_CURSOR ); END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_HOLDERID: { - val: body.P_HOLDERID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { VAL: body.P_SPID, TYPE: oracledb.DB_TYPE_NUMBER }, + P_HOLDERID: { VAL: body.P_HOLDERID, TYPE: oracledb.DB_TYPE_NUMBER }, + 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); - P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - return { P_CURSOR: P_CURSOR_rows }; + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { P_CURSOR: fres }; } catch (error) { handleError(error, ManageHoldersService.name) } finally { await closeOracleDbConnection(connection, ManageHoldersService.name) } }; + UpdateHolderContact = async (body: UpdateHolderContactDTO) => { const newBody = { - p_holdercontactid: null, - p_spid: null, - p_firstname: null, - p_lastname: null, - p_middleinitial: null, - p_title: null, - p_phone: null, - p_mobile: null, - p_fax: null, - p_emailaddress: null, - p_userid: null, + P_HOLDERCONTACTID: null, + P_SPID: null, + P_FIRSTNAME: null, + P_LASTNAME: null, + P_MIDDLEINITIAL: null, + P_TITLE: null, + P_PHONE: null, + P_MOBILE: null, + P_FAX: null, + P_EMAILADDRESS: null, + P_USERID: null, }; const reqBody = JSON.parse(JSON.stringify(body)); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach((key) => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === '') { - obj[key] = null; - } - }); - } - setEmptyStringsToNull(reqBody); const finalBody: UpdateHolderContactDTO = { ...newBody, ...reqBody }; - let connection: Connection | undefined = undefined; - let P_cursor_rows = []; + let connection; + try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result: Result = await connection.execute( - `BEGIN - MANAGEHOLDER_PKG.UpdateHolders( - :P_HOLDERCONTACTID, - :P_SPID, - :P_FIRSTNAME, - :P_LASTNAME, - :P_MIDDLEINITIAL, - :P_TITLE, - :P_PHONENO, - :P_MOBILENO, - :P_FAXNO, - :P_EMAILADDRESS, - :P_USERID, - :P_CURSOR - ); + `BEGIN + MANAGEHOLDER_PKG.UPDATEHOLDERS( + :P_HOLDERCONTACTID, :P_SPID, :P_FIRSTNAME, :P_LASTNAME, + :P_MIDDLEINITIAL, :P_TITLE, :P_PHONENO, :P_MOBILENO, + :P_FAXNO, :P_EMAILADDRESS, :P_USERID, :P_CURSOR + ); END;`, { - P_HOLDERCONTACTID: { - val: finalBody.P_HOLDERCONTACTID ? finalBody.P_HOLDERCONTACTID : null, - type: oracledb.DB_TYPE_NUMBER, - }, - P_SPID: { - val: finalBody.P_SPID ? finalBody.P_SPID : null, - type: oracledb.DB_TYPE_NUMBER, - }, - P_FIRSTNAME: { - val: finalBody.P_FIRSTNAME ? finalBody.P_FIRSTNAME : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_LASTNAME: { - val: finalBody.P_LASTNAME ? finalBody.P_LASTNAME : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_MIDDLEINITIAL: { - val: finalBody.P_MIDDLEINITIAL ? finalBody.P_MIDDLEINITIAL : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_TITLE: { - val: finalBody.P_TITLE ? finalBody.P_TITLE : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_PHONENO: { - val: finalBody.P_PHONENO ? finalBody.P_PHONENO : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_MOBILENO: { - val: finalBody.P_MOBILENO ? finalBody.P_MOBILENO : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_FAXNO: { - val: finalBody.P_FAXNO ? finalBody.P_FAXNO : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_EMAILADDRESS: { - val: finalBody.P_EMAILADDRESS ? finalBody.P_EMAILADDRESS : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_USERID: { - val: finalBody.P_USERID ? finalBody.P_USERID : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_HOLDERCONTACTID: { val: finalBody.P_HOLDERCONTACTID, type: oracledb.DB_TYPE_NUMBER }, + P_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_FIRSTNAME: { val: finalBody.P_FIRSTNAME, type: oracledb.DB_TYPE_NVARCHAR }, + P_LASTNAME: { val: finalBody.P_LASTNAME, type: oracledb.DB_TYPE_NVARCHAR }, + P_MIDDLEINITIAL: { val: finalBody.P_MIDDLEINITIAL, type: oracledb.DB_TYPE_NVARCHAR }, + P_TITLE: { val: finalBody.P_TITLE, type: oracledb.DB_TYPE_NVARCHAR }, + P_PHONENO: { val: finalBody.P_PHONENO, type: oracledb.DB_TYPE_NVARCHAR }, + P_MOBILENO: { val: finalBody.P_MOBILENO, type: oracledb.DB_TYPE_NVARCHAR }, + P_FAXNO: { val: finalBody.P_FAXNO, type: oracledb.DB_TYPE_NVARCHAR }, + P_EMAILADDRESS: { val: finalBody.P_EMAILADDRESS, type: oracledb.DB_TYPE_NVARCHAR }, + P_USERID: { val: finalBody.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT, @@ -753,21 +313,20 @@ export class ManageHoldersService { // let fres = await result.outBinds.P_cursor.getRows(); - if (result.outBinds && result.outBinds.P_cursor) { - const cursor = result.outBinds.P_cursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - P_cursor_rows = P_cursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - throw new Error('No cursor returned from the stored procedure'); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - return { P_cursor: P_cursor_rows }; + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { P_cursor: fres }; // return fres } catch (error) { @@ -776,300 +335,227 @@ export class ManageHoldersService { await closeOracleDbConnection(connection, ManageHoldersService.name) } }; + GetHolderContacts = async (body: GetHolderDTO) => { - let connection: Connection | undefined = undefined; - let P_CURSOR_rows = []; + let connection; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result: Result = await connection.execute( `BEGIN - MANAGEHOLDER_PKG.GetHolderContacts( - :P_SPID, - :P_HOLDERID, - :P_CURSOR - ); - END;`, + MANAGEHOLDER_PKG.GetHolderContacts( + :P_SPID, :P_HOLDERID, :P_CURSOR + ); + END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_HOLDERID: { - val: body.P_HOLDERID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_HOLDERID: { val: body.P_HOLDERID, type: oracledb.DB_TYPE_NUMBER }, + 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); - P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - return { P_CURSOR: P_CURSOR_rows }; + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { P_CURSOR: fres }; } catch (error) { handleError(error, ManageHoldersService.name) } finally { await closeOracleDbConnection(connection, ManageHoldersService.name) } }; + InactivateHolder = async (body: HolderActivateOrInactivateDTO) => { - let connection: Connection | undefined = undefined; - let P_CURSOR_rows = []; + let connection; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result: Result = await connection.execute( `BEGIN - ManageHolder_Pkg.InactivateHolder( - :P_SPID, - :P_HOLDERID, - :P_USERID, - :P_CURSOR - ); - END;`, + ManageHolder_Pkg.InactivateHolder( + :P_SPID, :P_HOLDERID, :P_USERID, :P_CURSOR + ); + END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_HOLDERID: { - val: body.P_HOLDERID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_HOLDERID: { val: body.P_HOLDERID, type: oracledb.DB_TYPE_NUMBER }, + 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, }, ); - if (result.outBinds && result.outBinds.P_CURSOR) { - const cursor = result.outBinds.P_CURSOR; - let rowsBatch; + await connection.commit(); - do { - rowsBatch = await cursor.getRows(100); - P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - return { P_CURSOR: P_CURSOR_rows }; + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { P_CURSOR: fres }; } catch (error) { handleError(error, ManageHoldersService.name) } finally { await closeOracleDbConnection(connection, ManageHoldersService.name) } }; + ReactivateHolder = async (body: HolderActivateOrInactivateDTO) => { - let connection: Connection | undefined = undefined; - let P_CURSOR_rows = []; + let connection; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result: Result = await connection.execute( `BEGIN - ManageHolder_Pkg.ReactivateHolder( - :P_SPID, - :P_HOLDERID, - :P_USERID, - :P_CURSOR - ); - END;`, + ManageHolder_Pkg.ReactivateHolder( + :P_SPID, :P_HOLDERID, :P_USERID, :P_CURSOR + ); + END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_HOLDERID: { - val: body.P_HOLDERID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_HOLDERID: { val: body.P_HOLDERID, type: oracledb.DB_TYPE_NUMBER }, + 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, }, ); - if (result.outBinds && result.outBinds.P_CURSOR) { - const cursor = result.outBinds.P_CURSOR; - let rowsBatch; + await connection.commit(); - do { - rowsBatch = await cursor.getRows(100); - P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - return { P_CURSOR: P_CURSOR_rows }; + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { P_CURSOR: fres }; } catch (error) { handleError(error, ManageHoldersService.name) } finally { await closeOracleDbConnection(connection, ManageHoldersService.name) } }; + InactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => { - let connection: Connection | undefined = undefined; - let P_CURSOR_rows = []; + let connection; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result: Result = await connection.execute( `BEGIN ManageHolder_Pkg.InactivateHolderContact( - :P_SPID, - :P_HOLDERCONTACTID, - :P_USERID, - :P_CURSOR + :P_SPID, :P_HOLDERCONTACTID, :P_USERID, :P_CURSOR ); END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_HOLDERCONTACTID: { - val: body.P_HOLDERCONTACTID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_HOLDERCONTACTID: { val: body.P_HOLDERCONTACTID, type: oracledb.DB_TYPE_NUMBER }, + 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, }, ); - if (result.outBinds && result.outBinds.P_CURSOR) { - const cursor = result.outBinds.P_CURSOR; - let rowsBatch; + await connection.commit(); - do { - rowsBatch = await cursor.getRows(100); - P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - return { P_CURSOR: P_CURSOR_rows }; + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { P_CURSOR: fres }; } catch (error) { handleError(error, ManageHoldersService.name) } finally { await closeOracleDbConnection(connection, ManageHoldersService.name) } }; + ReactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => { - let connection: Connection | undefined = undefined; - let P_CURSOR_rows = []; + let connection; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result: Result = await connection.execute( `BEGIN - ManageHolder_Pkg.ReactivateHolderContact( - :P_SPID, - :P_HOLDERCONTACTID, - :P_USERID, - :P_CURSOR - ); - END;`, + ManageHolder_Pkg.ReactivateHolderContact( + :P_SPID, :P_HOLDERCONTACTID, :P_USERID, :P_CURSOR + ); + END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_HOLDERCONTACTID: { - val: body.P_HOLDERCONTACTID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_USERID: { - val: body.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_HOLDERCONTACTID: { val: body.P_HOLDERCONTACTID, type: oracledb.DB_TYPE_NUMBER }, + 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, }, ); - if (result.outBinds && result.outBinds.P_CURSOR) { - const cursor = result.outBinds.P_CURSOR; - let rowsBatch; + await connection.commit(); - do { - rowsBatch = await cursor.getRows(100); - P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - return { P_CURSOR: P_CURSOR_rows }; + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { P_CURSOR: fres }; } catch (error) { handleError(error, ManageHoldersService.name) } finally { diff --git a/src/oracle/param-table/param-table.service.ts b/src/oracle/param-table/param-table.service.ts index b06db8e..da1627d 100644 --- a/src/oracle/param-table/param-table.service.ts +++ b/src/oracle/param-table/param-table.service.ts @@ -113,20 +113,12 @@ export class ParamTableService { 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, type: oracledb.DB_TYPE_NUMBER }, P_PARAMTYPE: { val: body.P_PARAMTYPE, type: oracledb.DB_TYPE_VARCHAR }, @@ -176,19 +168,12 @@ export class ParamTableService { 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, type: oracledb.DB_TYPE_NUMBER }, P_PARAMID: { val: body.P_PARAMID, type: oracledb.DB_TYPE_NUMBER }, 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 8f886ce..752868b 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 @@ -23,39 +23,18 @@ export class CarnetSequenceService { 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, - type: oracledb.DB_TYPE_NUMBER, - }, - P_REGIONID: { - val: body.P_REGIONID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_STARTNUMBER: { - val: body.P_STARTNUMBER, - type: oracledb.DB_TYPE_NUMBER, - }, - P_ENDNUMBER: { - val: body.P_ENDNUMBER, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CARNETTYPE: { - val: body.P_CARNETTYPE, - type: oracledb.DB_TYPE_VARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_REGIONID: { val: body.P_REGIONID, type: oracledb.DB_TYPE_NUMBER }, + P_STARTNUMBER: { val: body.P_STARTNUMBER, type: oracledb.DB_TYPE_NUMBER }, + P_ENDNUMBER: { val: body.P_ENDNUMBER, type: oracledb.DB_TYPE_NUMBER }, + P_CARNETTYPE: { val: body.P_CARNETTYPE, type: oracledb.DB_TYPE_VARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT, diff --git a/src/oracle/uscib-managed-sp/sp/sp.service.ts b/src/oracle/uscib-managed-sp/sp/sp.service.ts index c0bd25c..852e5f7 100644 --- a/src/oracle/uscib-managed-sp/sp/sp.service.ts +++ b/src/oracle/uscib-managed-sp/sp/sp.service.ts @@ -3,7 +3,7 @@ import { OracleDBService } from 'src/db/db.service'; import * as oracledb from 'oracledb'; import { BadRequestException } from 'src/exceptions/badRequest.exception'; import { InternalServerException } from 'src/exceptions/internalServerError.exception'; -import { closeOracleDbConnection, fetchCursor, handleError } from 'src/utils/helper'; +import { closeOracleDbConnection, fetchCursor, handleError, setEmptyStringsToNull } from 'src/utils/helper'; import { SPID_DTO, InsertNewServiceProviderDTO, @@ -37,16 +37,6 @@ export class SpService { const reqBody = JSON.parse(JSON.stringify(body)); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach((key) => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === '') { - obj[key] = null; - } - }); - } - setEmptyStringsToNull(reqBody); const finalBody: InsertNewServiceProviderDTO = { ...newBody, ...reqBody }; @@ -57,25 +47,14 @@ export class SpService { const result = await connection.execute( `BEGIN - USCIB_Managed_Pkg.InsertNewSP( - :P_NAME, - :P_LOOKUPCODE, - :P_ADDRESS1, - :P_ADDRESS2, - :P_CITY, - :P_STATE, - :P_ZIP, - :P_COUNTRY, - :P_ISSUINGREGION, - :P_REPLACEMENTREGION, - :P_BONDSURETY, - :P_CARGOPOLICYNO, - :P_CARGOSURETY, - :P_USER_ID, - :P_NOTES, - :P_FILEIDS, - :P_CURSOR); - END;`, + USCIB_Managed_Pkg.InsertNewSP( + :P_NAME, :P_LOOKUPCODE, :P_ADDRESS1, :P_ADDRESS2, + :P_CITY, :P_STATE, :P_ZIP, :P_COUNTRY, + :P_ISSUINGREGION, :P_REPLACEMENTREGION,:P_BONDSURETY, :P_CARGOPOLICYNO, + :P_CARGOSURETY, :P_USER_ID, :P_NOTES, :P_FILEIDS, + :P_CURSOR + ); + END;`, { P_NAME: { val: finalBody.P_NAME, type: oracledb.DB_TYPE_VARCHAR }, P_LOOKUPCODE: { val: finalBody.P_LOOKUPCODE, type: oracledb.DB_TYPE_VARCHAR }, @@ -143,16 +122,6 @@ export class SpService { const reqBody = JSON.parse(JSON.stringify(body)); - function setEmptyStringsToNull(obj) { - Object.keys(obj).forEach((key) => { - if (typeof obj[key] === 'object' && obj[key] !== null) { - setEmptyStringsToNull(obj[key]); - } else if (obj[key] === '') { - obj[key] = null; - } - }); - } - setEmptyStringsToNull(reqBody); const finalBody: UpdateServiceProviderDTO = { ...newBody, ...reqBody }; @@ -163,26 +132,14 @@ export class SpService { const result = await connection.execute( `BEGIN - USCIB_Managed_Pkg.UpdateSP( - :P_SPID, - :P_NAME, - :P_LOOKUPCODE, - :P_ADDRESS1, - :P_ADDRESS2, - :P_CITY, - :P_STATE, - :P_ZIP, - :P_COUNTRY, - :P_ISSUINGREGION, - :P_REPLACEMENTREGION, - :P_BONDSURETY, - :P_CARGOPOLICYNO, - :P_CARGOSURETY, - :P_USER_ID, - :P_NOTES, - :P_FILEIDS, - :P_CURSOR); - END;`, + USCIB_Managed_Pkg.UpdateSP( + :P_SPID, :P_NAME, :P_LOOKUPCODE, :P_ADDRESS1, + :P_ADDRESS2, :P_CITY, :P_STATE, :P_ZIP, + :P_COUNTRY, :P_ISSUINGREGION, :P_REPLACEMENTREGION, :P_BONDSURETY, + :P_CARGOPOLICYNO, :P_CARGOSURETY, :P_USER_ID, :P_NOTES, + :P_FILEIDS, :P_CURSOR + ); + END;`, { P_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER }, P_NAME: { val: finalBody.P_NAME, type: oracledb.DB_TYPE_VARCHAR },