diff --git a/src/dto/manage-clients/manage-clients-property.dto.ts b/src/dto/manage-clients/manage-clients-property.dto.ts index 6fe6d4c..f94d961 100644 --- a/src/dto/manage-clients/manage-clients-property.dto.ts +++ b/src/dto/manage-clients/manage-clients-property.dto.ts @@ -1,5 +1,5 @@ import { ApiProperty, IntersectionType, PartialType } from "@nestjs/swagger"; -import { Type } from "class-transformer"; +import { Transform, Type } from "class-transformer"; import { IsArray, IsDefined, IsInt, IsNumber, IsString, Length, Max, Min, ValidateNested } from "class-validator"; import { @@ -11,12 +11,13 @@ import { export class CLIENTID_DTO { @ApiProperty({ required: true }) @Max(999999999, { - message: 'Property p_clientid must not exceed 999999999', + message: 'Property P_CLIENTID must not exceed 999999999', }) - @Min(0, { message: 'Property p_clientid must be at least 0 or more' }) - @IsInt({ message: 'Property p_clientid allows only whole numbers' }) - @IsNumber({}, { message: 'Property p_clientid must be a number' }) - @IsDefined({ message: 'Property p_clientid is required' }) + @Min(0, { message: 'Property P_CLIENTID must be at least 0 or more' }) + @IsInt({ message: 'Property P_CLIENTID allows only whole numbers' }) + @IsNumber({}, { message: 'Property P_CLIENTID must be a number' }) + @Transform(({ value }) => Number(value)) + @IsDefined({ message: 'Property P_CLIENTID is required' }) P_CLIENTID: number; } diff --git a/src/dto/manage-clients/manage-clients.dto.ts b/src/dto/manage-clients/manage-clients.dto.ts index 4935656..ea8ab16 100644 --- a/src/dto/manage-clients/manage-clients.dto.ts +++ b/src/dto/manage-clients/manage-clients.dto.ts @@ -75,6 +75,18 @@ export class GetPreparersDTO extends IntersectionType( STATUS_DTO ) { } +export class GetPreparersParamDTO extends IntersectionType( + SPID_DTO, + STATUS_DTO +) { } + +export class GetPreparersQueryDTO extends IntersectionType( + PartialType(NAME_DTO), + PartialType(LOOKUP_CODE_DTO), + PartialType(CITY_DTO), + PartialType(STATE_DTO), +) { } + export class UpdateClientLocationsDTO extends IntersectionType( SPID_DTO, CLIENTLOCATIONID_DTO, @@ -103,7 +115,7 @@ export class CreateClientLocationsDTO extends IntersectionType( USERID_DTO ) { } -export class GetPreparerByClientidContactsByClientidLocByClientidDTO extends IntersectionType( +export class GetClientDTO extends IntersectionType( SPID_DTO, CLIENTID_DTO ) { } diff --git a/src/mssql/manage-clients/manage-clients.controller.ts b/src/mssql/manage-clients/manage-clients.controller.ts index 5d340ff..c706862 100644 --- a/src/mssql/manage-clients/manage-clients.controller.ts +++ b/src/mssql/manage-clients/manage-clients.controller.ts @@ -4,7 +4,7 @@ import { ApiTags } from '@nestjs/swagger'; import { CreateClientContactsDTO, CreateClientDataDTO, - CreateClientLocationsDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, + CreateClientLocationsDTO, GetClientDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from 'src/dto/manage-clients/manage-clients.dto'; @@ -57,7 +57,7 @@ export class ManageClientsController { @ApiTags('Manage Clients - Mssql') @Get('GetPreparerByClientid') GetPreparerByClientid( - @Query() body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + @Query() body: GetClientDTO, ) { return this.manageClientsService.GetPreparerByClientid(body); } @@ -65,7 +65,7 @@ export class ManageClientsController { @ApiTags('Manage Clients - Mssql') @Get('GetPreparerContactsByClientid') GetPreparerContactsByClientid( - @Query() body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + @Query() body: GetClientDTO, ) { return this.manageClientsService.GetPreparerContactsByClientid(body); } @@ -73,7 +73,7 @@ export class ManageClientsController { @ApiTags('Manage Clients - Mssql') @Get('GetPreparerLocByClientid') GetPreparerLocByClientid( - @Query() body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + @Query() body: GetClientDTO, ) { return this.manageClientsService.GetPreparerLocByClientid(body); } diff --git a/src/mssql/manage-clients/manage-clients.service.ts b/src/mssql/manage-clients/manage-clients.service.ts index 07eefb3..4ffe384 100644 --- a/src/mssql/manage-clients/manage-clients.service.ts +++ b/src/mssql/manage-clients/manage-clients.service.ts @@ -4,7 +4,8 @@ import { MssqlDBService } from 'src/db/db.service'; import * as mssql from 'mssql'; import { CreateClientContactsDTO, CreateClientDataDTO, - CreateClientLocationsDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, + CreateClientLocationsDTO, + GetClientDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from 'src/dto/manage-clients/manage-clients.dto'; @@ -96,7 +97,7 @@ export class ManageClientsService { } }; - GetPreparerByClientid = async (body: GetPreparerByClientidContactsByClientidLocByClientidDTO) => { + GetPreparerByClientid = async (body: GetClientDTO) => { let connection: Connection; try { connection = await this.mssqlDBService.getConnection(); @@ -473,7 +474,7 @@ export class ManageClientsService { }; GetPreparerContactsByClientid = async ( - body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + body: GetClientDTO, ) => { const newBody = { @@ -499,7 +500,7 @@ export class ManageClientsService { setEmptyStringsToNull(reqBody); - const finalBody: GetPreparerByClientidContactsByClientidLocByClientidDTO = { + const finalBody: GetClientDTO = { ...newBody, ...reqBody, }; @@ -522,7 +523,7 @@ export class ManageClientsService { }; GetPreparerLocByClientid = async ( - body: GetPreparerByClientidContactsByClientidLocByClientidDTO, + body: GetClientDTO, ) => { const newBody = { P_SPID: null, @@ -547,7 +548,7 @@ export class ManageClientsService { setEmptyStringsToNull(reqBody); - const finalBody: GetPreparerByClientidContactsByClientidLocByClientidDTO = { + const finalBody: GetClientDTO = { ...newBody, ...reqBody, }; diff --git a/src/oracle/manage-clients/manage-clients.controller.ts b/src/oracle/manage-clients/manage-clients.controller.ts index b4118fe..f636c7d 100644 --- a/src/oracle/manage-clients/manage-clients.controller.ts +++ b/src/oracle/manage-clients/manage-clients.controller.ts @@ -1,11 +1,12 @@ -import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common'; +import { Body, Controller, Get, Param, Post, Put, Query } from '@nestjs/common'; import { ManageClientsService } from './manage-clients.service'; import { ApiTags } from '@nestjs/swagger'; import { CreateClientContactsDTO, CreateClientDataDTO, - CreateClientLocationsDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, - GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO + CreateClientLocationsDTO, + GetClientDTO, + GetPreparersParamDTO, GetPreparersQueryDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from 'src/dto/property.dto'; @Controller('oracle') @@ -49,32 +50,26 @@ export class ManageClientsController { } @ApiTags('Manage Clients - Oracle') - @Get('GetPreparers') - async GetPreparers(@Query() query: GetPreparersDTO) { - return await this.manageClientsService.GetPreparers(query); + @Get('GetPreparers/:P_SPID/:P_STATUS') + async GetPreparers(@Param() param: GetPreparersParamDTO, @Query() query: GetPreparersQueryDTO) { + return await this.manageClientsService.GetPreparers({ ...param, ...query }); } @ApiTags('Manage Clients - Oracle') - @Get('GetPreparerByClientid') - GetPreparerByClientid( - @Query() body: GetPreparerByClientidContactsByClientidLocByClientidDTO, - ) { + @Get('GetPreparerByClientid/:P_SPID/:P_CLIENTID') + GetPreparerByClientid(@Param() body: GetClientDTO) { return this.manageClientsService.GetPreparerByClientid(body); } @ApiTags('Manage Clients - Oracle') - @Get('GetPreparerContactsByClientid') - GetPreparerContactsByClientid( - @Query() body: GetPreparerByClientidContactsByClientidLocByClientidDTO, - ) { + @Get('GetPreparerContactsByClientid/:P_SPID/:P_CLIENTID') + GetPreparerContactsByClientid(@Param() body: GetClientDTO) { return this.manageClientsService.GetPreparerContactsByClientid(body); } @ApiTags('Manage Clients - Oracle') - @Get('GetPreparerLocByClientid') - GetPreparerLocByClientid( - @Query() body: GetPreparerByClientidContactsByClientidLocByClientidDTO, - ) { + @Get('GetPreparerLocByClientid/:P_SPID/:P_CLIENTID') + GetPreparerLocByClientid(@Param() body: GetClientDTO) { return this.manageClientsService.GetPreparerLocByClientid(body); } } diff --git a/src/oracle/manage-clients/manage-clients.dto.ts b/src/oracle/manage-clients/manage-clients.dto.ts deleted file mode 100644 index 10a45ba..0000000 --- a/src/oracle/manage-clients/manage-clients.dto.ts +++ /dev/null @@ -1,613 +0,0 @@ -// import { ApiProperty } from '@nestjs/swagger'; -// import { -// IsDefined, -// IsInt, -// IsNumber, -// IsOptional, -// IsString, -// Length, -// Max, -// Min, -// ValidateNested, -// IsArray, -// IsEmail, -// } from 'class-validator'; -// import { Transform, Type } from 'class-transformer'; -// import { CONTACTSTABLE_ROW_DTO } from 'src/dto/holder/holder.dto'; - -// export class p_clientlocaddresstableDTO { -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property Nameof must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property Nameof must be a string' }) -// @IsDefined({ message: 'Property Nameof is required' }) -// Nameof: string; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property Address1 must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property Address1 must be a string' }) -// @IsDefined({ message: 'Property Address1 is required' }) -// Address1: string; - -// @ApiProperty({ required: false }) -// @Length(0, 50, { -// message: 'Property Address2 must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property Address2 must be a string' }) -// @IsOptional() -// Address2?: string; - -// @ApiProperty({ required: true }) -// @Length(0, 30, { -// message: 'Property City must be between 0 to 30 characters', -// }) -// @IsString({ message: 'Property City must be a string' }) -// @IsDefined({ message: 'Property City is required' }) -// City: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { message: 'Property State must be between 0 to 2 characters' }) -// @IsString({ message: 'Property State must be a string' }) -// @IsDefined({ message: 'Property State is required' }) -// State: string; - -// @ApiProperty({ required: true }) -// @Length(0, 10, { message: 'Property Zip must be between 0 to 10 characters' }) -// @IsString({ message: 'Property Zip must be a string' }) -// @IsDefined({ message: 'Property Zip is required' }) -// Zip: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property Country must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property Country must be a string' }) -// @IsDefined({ message: 'Property Country is required' }) -// Country: string; -// } - -// export class CreateClientDataDTO { -// @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({ message: 'Property p_spid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// p_spid: number; - -// @ApiProperty({ required: true }) -// // @Max(999999999, { message: "Property p_clientname must not exceed 999999999" }) -// // @Min(0, { message: "Property p_clientname must be at least 0 or more" }) -// // @IsInt({ message: "Property p_clientname allows only whole numbers" }) -// // @IsNumber({}, { message: "Property p_clientname must be a number" }) -// // @IsDefined({ message: "Property p_clientname is required" }) -// @Length(0, 50, { -// message: 'Property p_clientname must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_clientname must be a string' }) -// @IsDefined({ message: 'Property p_clientname is required' }) -// p_clientname: string; - -// @ApiProperty({ required: true }) -// @Length(0, 20, { -// message: 'Property p_lookupcode must be between 0 to 20 characters', -// }) -// @IsString({ message: 'Property p_lookupcode must be a string' }) -// @IsDefined({ message: 'Property p_lookupcode is required' }) -// p_lookupcode: string; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_address1 must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_address1 must be a string' }) -// @IsDefined({ message: 'Property p_address1 is required' }) -// p_address1: string; - -// @ApiProperty({ required: false }) -// @Length(0, 50, { -// message: 'Property p_address2 must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_address2 must be a string' }) -// @IsOptional() -// p_address2?: string; - -// @ApiProperty({ required: true }) -// @Length(0, 30, { -// message: 'Property p_city must be between 0 to 30 characters', -// }) -// @IsString({ message: 'Property p_city must be a string' }) -// @IsDefined({ message: 'Property p_city is required' }) -// p_city: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property p_state must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_state must be a string' }) -// @IsDefined({ message: 'Property p_state is required' }) -// p_state: string; - -// @ApiProperty({ required: false }) -// @Length(0, 10, { -// message: 'Property p_zip must be between 0 to 10 characters', -// }) -// @IsString({ message: 'Property p_zip must be a string' }) -// @IsOptional() -// p_zip?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 2, { -// message: 'Property p_country must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_country must be a string' }) -// @IsOptional() -// p_country?: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property p_issuingregion must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_issuingregion must be a string' }) -// @IsDefined({ message: 'Property p_issuingregion is required' }) -// p_issuingregion: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property p_revenuelocation must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_revenuelocation must be a string' }) -// @IsDefined({ message: 'Property p_revenuelocation is required' }) -// p_revenuelocation: string; - -// @ApiProperty({ required: true }) -// @Length(0, 100, { -// message: 'Property p_userid must be between 0 to 100 characters', -// }) -// @IsString({ message: 'Property p_userid must be a string' }) -// @IsDefined({ message: 'Property p_userid is required' }) -// p_userid: string; - -// // @ApiProperty({ required: true, type: () => [p_contactstableDTO] }) -// // @Type(() => p_contactstableDTO) -// // @ValidateNested({ each: true }) -// // @IsArray({ message: 'Property p_contactstable allows only array type' }) -// // @IsDefined({ message: 'Property p_contactstable is required' }) -// // p_contactstable: p_contactstableDTO[]; - -// // @ApiProperty({ required: true, type: () => [p_clientlocaddresstableDTO] }) -// // @Type(() => p_clientlocaddresstableDTO) -// // @ValidateNested({ each: true }) -// // @IsArray({ -// // message: 'Property p_clientlocaddresstable allows only array type', -// // }) -// // @IsDefined({ message: 'Property p_clientlocaddresstable is required' }) -// // p_clientlocaddresstable: p_clientlocaddresstableDTO[]; -// } - -// export class UpdateClientDTO { -// @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({ message: 'Property p_spid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// 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({ message: 'Property p_clientid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_clientid must be a number' }) -// @IsDefined({ message: 'Property p_clientid is required' }) -// p_clientid: number; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_preparername must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_preparername must be a string' }) -// @IsDefined({ message: 'Property p_preparername is required' }) -// p_preparername: string; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_address1 must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_address1 must be a string' }) -// @IsDefined({ message: 'Property p_address1 is required' }) -// p_address1: string; - -// @ApiProperty({ required: false }) -// @Length(0, 50, { -// message: 'Property p_address2 must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_address2 must be a string' }) -// @IsOptional() -// p_address2?: string; - -// @ApiProperty({ required: true }) -// @Length(0, 30, { -// message: 'Property p_city must be between 0 to 30 characters', -// }) -// @IsString({ message: 'Property p_city must be a string' }) -// @IsDefined({ message: 'Property p_city is required' }) -// p_city: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property p_state must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_state must be a string' }) -// @IsDefined({ message: 'Property p_state is required' }) -// p_state: string; - -// @ApiProperty({ required: true }) -// @Length(0, 10, { -// message: 'Property p_zip must be between 0 to 10 characters', -// }) -// @IsString({ message: 'Property p_zip must be a string' }) -// @IsDefined({ message: 'Property p_zip is required' }) -// p_zip: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property p_country must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_country must be a string' }) -// @IsDefined({ message: 'Property p_country is required' }) -// p_country: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property p_revenuelocation must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_revenuelocation must be a string' }) -// @IsDefined({ message: 'Property p_revenuelocation is required' }) -// p_revenuelocation: string; - -// @ApiProperty({ required: true }) -// @Length(0, 100, { -// message: 'Property p_userid must be between 0 to 100 characters', -// }) -// @IsString({ message: 'Property p_userid must be a string' }) -// @IsDefined({ message: 'Property p_userid is required' }) -// p_userid: string; -// } - -// export class UpdateClientContactsDTO { -// @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({ message: 'Property p_spid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// p_spid: number; - -// @ApiProperty({ required: true }) -// @Max(999999999, { -// message: 'Property p_clientcontactid must not exceed 999999999', -// }) -// @Min(0, { message: 'Property p_clientcontactid must be at least 0 or more' }) -// @IsInt({ message: 'Property p_clientcontactid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_clientcontactid must be a number' }) -// @IsDefined({ message: 'Property p_clientcontactid is required' }) -// p_clientcontactid: number; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_firstname must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_firstname must be a string' }) -// @IsDefined({ message: 'Property p_firstname is required' }) -// p_firstname: string; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_lastname must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_lastname must be a string' }) -// @IsDefined({ message: 'Property p_lastname is required' }) -// p_lastname: string; - -// @ApiProperty({ required: false }) -// @Length(0, 3, { -// message: 'Property p_middleinitial must be between 0 to 3 characters', -// }) -// @IsString({ message: 'Property p_middleinitial must be a string' }) -// @IsOptional() -// p_middleinitial?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 50, { -// message: 'Property p_title must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_title must be a string' }) -// @IsOptional() -// p_title?: string; - -// @ApiProperty({ required: true }) -// @Length(0, 20, { -// message: 'Property p_phone must be between 0 to 20 characters', -// }) -// @IsString({ message: 'Property p_phone must be a string' }) -// @IsDefined({ message: 'Property p_phone is required' }) -// p_phone: string; - -// @ApiProperty({ required: true }) -// @Length(0, 20, { -// message: 'Property p_fax must be between 0 to 20 characters', -// }) -// @IsString({ message: 'Property p_fax must be a string' }) -// @IsDefined({ message: 'Property p_fax is required' }) -// p_fax: string; - -// @ApiProperty({ required: false }) -// @Length(0, 20, { -// message: 'Property p_mobileno must be between 0 to 20 characters', -// }) -// @IsString({ message: 'Property p_mobileno must be a string' }) -// @IsOptional() -// p_mobileno?: string; - -// @ApiProperty({ required: true }) -// @Length(0, 100, { -// message: 'Property p_emailaddress must be between 0 to 100 characters', -// }) -// @IsEmail( -// {}, -// { message: 'Property p_emailaddress must be a valid email address' }, -// ) -// @IsDefined({ message: 'Property p_emailaddress is required' }) -// p_emailaddress: string; - -// @ApiProperty({ required: true }) -// @Length(0, 100, { -// message: 'Property p_userid must be between 0 to 100 characters', -// }) -// @IsString({ message: 'Property p_userid must be a string' }) -// @IsDefined({ message: 'Property p_userid is required' }) -// p_userid: string; -// } - -// export class GetPreparersDTO { -// @ApiProperty({ required: true }) -// @Transform(({ value }) => Number(value)) -// @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_spid must be at least 0 or more' }) -// @IsInt({ message: 'Property p_spid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// p_spid: number; - -// @ApiProperty({ required: false }) -// @Length(0, 50, { -// message: 'Property p_name must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_name must be a string' }) -// @IsOptional() -// p_name?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 30, { -// message: 'Property p_lookupcode must be between 0 to 30 characters', -// }) -// @IsString({ message: 'Property p_lookupcode must be a string' }) -// @IsOptional() -// p_lookupcode?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 20, { -// message: 'Property p_city must be between 0 to 20 characters', -// }) -// @IsString({ message: 'Property p_city must be a string' }) -// @IsOptional() -// p_city?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 2, { -// message: 'Property p_state must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_state must be a string' }) -// @IsOptional() -// p_state?: string; - -// @ApiProperty({ required: true }) -// @Length(0, 10, { -// message: 'Property p_status must be between 0 to 10 characters', -// }) -// @IsString({ message: 'Property p_status must be a string' }) -// @IsDefined({ message: 'Property p_status is required' }) -// p_status: string; -// } - -// export class UpdateClientLocationsDTO { -// @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({ message: 'Property p_spid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// p_spid: number; - -// @ApiProperty({ required: true }) -// @Max(999999999, { -// message: 'Property p_clientlocationid must not exceed 999999999', -// }) -// @Min(0, { message: 'Property p_clientlocationid must be at least 0 or more' }) -// @IsInt({ message: 'Property p_clientlocationid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_clientlocationid must be a number' }) -// @IsDefined({ message: 'Property p_clientlocationid is required' }) -// p_clientlocationid: number; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_lcoationname must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_lcoationname must be a string' }) -// @IsDefined({ message: 'Property p_lcoationname is required' }) -// p_lcoationname: string; - -// @ApiProperty({ required: true }) -// @Length(0, 50, { -// message: 'Property p_address1 must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_address1 must be a string' }) -// @IsDefined({ message: 'Property p_address1 is required' }) -// p_address1: string; - -// @ApiProperty({ required: false }) -// @Length(0, 50, { -// message: 'Property p_address2 must be between 0 to 50 characters', -// }) -// @IsString({ message: 'Property p_address2 must be a string' }) -// @IsOptional() -// p_address2?: string; - -// @ApiProperty({ required: false }) -// @Length(0, 30, { -// message: 'Property p_city must be between 0 to 30 characters', -// }) -// @IsString({ message: 'Property p_city must be a string' }) -// @IsOptional() -// p_city?: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property p_state must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_state must be a string' }) -// @IsDefined({ message: 'Property p_state is required' }) -// p_state: string; - -// @ApiProperty({ required: true }) -// @Length(0, 10, { -// message: 'Property p_zip must be between 0 to 10 characters', -// }) -// @IsString({ message: 'Property p_zip must be a string' }) -// @IsDefined({ message: 'Property p_zip is required' }) -// p_zip: string; - -// @ApiProperty({ required: true }) -// @Length(0, 2, { -// message: 'Property p_country must be between 0 to 2 characters', -// }) -// @IsString({ message: 'Property p_country must be a string' }) -// @IsDefined({ message: 'Property p_country is required' }) -// p_country: string; - -// @ApiProperty({ required: true }) -// @Length(0, 100, { -// message: 'Property p_userid must be between 0 to 100 characters', -// }) -// @IsString({ message: 'Property p_userid must be a string' }) -// @IsDefined({ message: 'Property p_userid is required' }) -// p_userid: string; -// } - -// export class CreateClientContactsDTO { -// @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({ message: 'Property p_spid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// 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({ message: 'Property p_clientid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_clientid must be a number' }) -// @IsDefined({ message: 'Property p_clientid is required' }) -// p_clientid: number; - -// @ApiProperty({ required: true, type: () => [CONTACTSTABLE_ROW_DTO] }) -// @Type(() => CONTACTSTABLE_ROW_DTO) -// @ValidateNested({ each: true }) -// @IsArray({ message: 'Property p_contactstable allows only array type' }) -// @IsDefined({ message: 'Property p_contactstable is required' }) -// p_contactstable: CONTACTSTABLE_ROW_DTO[]; - -// @ApiProperty({ required: true }) -// @Length(0, 1, { -// message: 'Property p_defcontactflag must be exactly 1 character', -// }) -// @IsString({ message: 'Property p_defcontactflag must be a string' }) -// @IsDefined({ message: 'Property p_defcontactflag is required' }) -// p_defcontactflag: string; - -// @ApiProperty({ required: true }) -// @Length(0, 100, { -// message: 'Property p_userid must be between 0 to 100 characters', -// }) -// @IsString({ message: 'Property p_userid must be a string' }) -// @IsDefined({ message: 'Property p_userid is required' }) -// p_userid: string; -// } - -// export class CreateClientLocationsDTO { -// @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({ message: 'Property p_spid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// 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({ message: 'Property p_clientid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_clientid must be a number' }) -// @IsDefined({ message: 'Property p_clientid is required' }) -// p_clientid: number; - -// @ApiProperty({ required: true, type: () => [p_clientlocaddresstableDTO] }) -// @Type(() => p_clientlocaddresstableDTO) -// @ValidateNested({ each: true }) -// @IsArray({ -// message: 'Property p_clientlocaddresstable allows only array type', -// }) -// @IsDefined({ message: 'Property p_clientlocaddresstable is required' }) -// p_clientlocaddresstable: p_clientlocaddresstableDTO[]; - -// // @ApiProperty({ required: true }) -// // @Length(0, 1, { -// // message: 'Property p_defcontactflag must be exactly 1 character', -// // }) -// // @IsString({ message: 'Property p_defcontactflag must be a string' }) -// // @IsDefined({ message: 'Property p_defcontactflag is required' }) -// // p_defcontactflag: string; - -// @ApiProperty({ required: true }) -// @Length(0, 100, { -// message: 'Property p_userid must be between 0 to 100 characters', -// }) -// @IsString({ message: 'Property p_userid must be a string' }) -// @IsDefined({ message: 'Property p_userid is required' }) -// p_userid: string; -// } - -// export class GetPreparerByClientidContactsByClientidLocByClientidDTO { -// @ApiProperty({ required: true }) -// @Transform(({ value }) => Number(value)) -// @Max(999999999, { message: 'Property p_spid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_spid must be at least 0 or more' }) -// @IsInt({ message: 'Property p_spid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_spid must be a number' }) -// @IsDefined({ message: 'Property p_spid is required' }) -// p_spid: number; - -// @ApiProperty({ required: true }) -// @Transform(({ value }) => Number(value)) -// @Max(999999999, { message: 'Property p_clientid must not exceed 999999999' }) -// @Min(0, { message: 'Property p_clientid must be at least 0 or more' }) -// @IsInt({ message: 'Property p_clientid allows only whole numbers' }) -// @IsNumber({}, { message: 'Property p_clientid must be a number' }) -// @IsDefined({ message: 'Property p_clientid is required' }) -// p_clientid: number; -// } diff --git a/src/oracle/manage-clients/manage-clients.service.ts b/src/oracle/manage-clients/manage-clients.service.ts index d7ccb9c..a374c2c 100644 --- a/src/oracle/manage-clients/manage-clients.service.ts +++ b/src/oracle/manage-clients/manage-clients.service.ts @@ -4,20 +4,24 @@ 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 { - CLIENTLOCADDRESSTABLE_ROW_DTO, CreateClientContactsDTO, CreateClientDataDTO, - CreateClientLocationsDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, + CreateClientContactsDTO, CreateClientDataDTO, + CreateClientLocationsDTO, + GetClientDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO, - CONTACTSTABLE_ROW_DTO } from 'src/dto/property.dto'; +import { OracleService } from '../oracle.service'; @Injectable() export class ManageClientsService { private readonly logger = new Logger(ManageClientsService.name); - constructor(private readonly oracleDBService: OracleDBService) { } + constructor( + private readonly oracleDBService: OracleDBService, + private readonly oracleService: OracleService + ) { } CreateClientData = async (body: CreateClientDataDTO) => { const newBody = { @@ -37,102 +41,38 @@ export class ManageClientsService { 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: CreateClientDataDTO = { ...newBody, ...reqBody }; let connection; - let P_CLIENTCURSOR_ROWS: any = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result = await connection.execute( `BEGIN - MANAGEPREPARER_PKG.CreateClientData( - :P_SPID, - :P_CLIENTNAME, - :P_LOOKUPCODE, - :P_ADDRESS1, - :P_ADDRESS2, - :P_CITY, - :P_STATE, - :P_ZIP, - :P_COUNTRY, - :P_ISSUINGREGION, - :P_REVENUELOCATION, - :P_USERID, - :P_CLIENTCURSOR - ); - END;`, + MANAGEPREPARER_PKG.CreateClientData( + :P_SPID, :P_CLIENTNAME, :P_LOOKUPCODE, :P_ADDRESS1, + :P_ADDRESS2, :P_CITY, :P_STATE, :P_ZIP, + :P_COUNTRY, :P_ISSUINGREGION, :P_REVENUELOCATION, :P_USERID, + :P_CLIENTCURSOR + ); + END;`, { - P_SPID: { - val: finalBody.P_SPID ? finalBody.P_SPID : null, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CLIENTNAME: { - val: finalBody.P_CLIENTNAME ? finalBody.P_CLIENTNAME : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_LOOKUPCODE: { - val: finalBody.P_LOOKUPCODE ? finalBody.P_LOOKUPCODE : 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_ISSUINGREGION: { - val: finalBody.P_ISSUINGREGION ? finalBody.P_ISSUINGREGION : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_REVENUELOCATION: { - val: finalBody.P_REVENUELOCATION - ? finalBody.P_REVENUELOCATION - : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_USERID: { - val: finalBody.P_USERID ? finalBody.P_USERID : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CLIENTCURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - } + P_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTNAME: { val: finalBody.P_CLIENTNAME, type: oracledb.DB_TYPE_NVARCHAR }, + P_LOOKUPCODE: { val: finalBody.P_LOOKUPCODE, 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_ISSUINGREGION: { val: finalBody.P_ISSUINGREGION, type: oracledb.DB_TYPE_NVARCHAR }, + P_REVENUELOCATION: { val: finalBody.P_REVENUELOCATION, type: oracledb.DB_TYPE_NVARCHAR }, + P_USERID: { val: finalBody.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + P_CLIENTCURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT, @@ -141,41 +81,25 @@ export class ManageClientsService { await connection.commit(); - if (result.outBinds && result.outBinds.P_CLIENTCURSOR) { - const cursor = result.outBinds.P_CLIENTCURSOR; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - P_CLIENTCURSOR_ROWS = P_CLIENTCURSOR_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_CLIENTCURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); } - if (P_CLIENTCURSOR_ROWS.length > 0 && P_CLIENTCURSOR_ROWS[0].ERRORMESG) { - throw new BadRequestException(P_CLIENTCURSOR_ROWS[0].ERRORMESG); + const fres: any = await fetchCursor(outBinds.P_CLIENTCURSOR, ManageClientsService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return { statusCode: 201, message: "Created Successfully" }; + return { statusCode: 201, message: "Created Successfully", ...fres[0] }; } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('CREATECLIENTDATA failed', error.stack || error); - throw new InternalServerException(); + handleError(error, ManageClientsService.name) } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } + await closeOracleDbConnection(connection, ManageClientsService.name) } }; @@ -196,96 +120,35 @@ export class ManageClientsService { 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: UpdateClientDTO = { ...newBody, ...reqBody }; let connection; - let P_CURSOR_rows: any = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result = await connection.execute( `BEGIN - MANAGEPREPARER_PKG.UpdateClient( - :P_SPID, - :P_CLIENTID, - :P_PREPARERNAME, - :P_ADDRESS1, - :P_ADDRESS2, - :P_CITY, - :P_STATE, - :P_ZIP, - :P_COUNTRY, - :P_REVENUELOCATION, - :P_USERID, - :P_CURSOR - ); - END;`, + MANAGEPREPARER_PKG.UpdateClient( + :P_SPID, :P_CLIENTID, :P_PREPARERNAME, :P_ADDRESS1, + :P_ADDRESS2, :P_CITY, :P_STATE, :P_ZIP, + :P_COUNTRY, :P_REVENUELOCATION, :P_USERID, :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_PREPARERNAME: { - val: finalBody.P_PREPARERNAME ? finalBody.P_PREPARERNAME : 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_REVENUELOCATION: { - val: finalBody.P_REVENUELOCATION - ? finalBody.P_REVENUELOCATION - : 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_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTID: { val: finalBody.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER }, + P_PREPARERNAME: { val: finalBody.P_PREPARERNAME, 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_REVENUELOCATION: { val: finalBody.P_REVENUELOCATION, 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, @@ -293,41 +156,25 @@ export class ManageClientsService { ); await connection.commit(); - 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."); } - if (P_CURSOR_rows.length > 0 && P_CURSOR_rows[0].ERRORMESG) { - throw new BadRequestException(P_CURSOR_rows[0].ERRORMESG); + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return { statusCode: 200, message: "Updated Successfully" }; + return { statusCode: 200, message: "Updated Successfully", ...fres[0] }; } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('UpdateClient failed', error.stack || error); - throw new InternalServerException(); + handleError(error, ManageClientsService.name) } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } + await closeOracleDbConnection(connection, ManageClientsService.name) } }; @@ -348,16 +195,6 @@ export class ManageClientsService { 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: UpdateClientContactsDTO = { ...newBody, ...reqBody }; @@ -366,78 +203,28 @@ export class ManageClientsService { let P_CURSOR_rows: any = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result = await connection.execute( `BEGIN - MANAGEPREPARER_PKG.UpdateClientContacts( - :P_SPID, - :P_CLIENTCONTACTID, - :P_FIRSTNAME, - :P_LASTNAME, - :P_MIDDLEINITIAL, - :P_TITLE, - :P_PHONENO, - :P_FAXNO, - :P_MOBILENO, - :P_EMAILADDRESS, - :P_USERID, - :P_cursor - ); - END;`, + MANAGEPREPARER_PKG.UpdateClientContacts( + :P_SPID, :P_CLIENTCONTACTID, :P_FIRSTNAME, :P_LASTNAME, + :P_MIDDLEINITIAL, :P_TITLE, :P_PHONENO, :P_FAXNO, + :P_MOBILENO, :P_EMAILADDRESS, :P_USERID, :P_CURSOR + ); + END;`, { - P_SPID: { - val: finalBody.P_SPID ? finalBody.P_SPID : null, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CLIENTCONTACTID: { - val: finalBody.P_CLIENTCONTACTID - ? finalBody.P_CLIENTCONTACTID - : 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_FAXNO: { - val: finalBody.P_FAXNO ? finalBody.P_FAXNO : null, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_MOBILENO: { - val: finalBody.P_MOBILENO ? finalBody.P_MOBILENO : 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_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTCONTACTID: { val: finalBody.P_CLIENTCONTACTID, 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_FAXNO: { val: finalBody.P_FAXNO, type: oracledb.DB_TYPE_NVARCHAR }, + P_MOBILENO: { val: finalBody.P_MOBILENO, 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, @@ -445,40 +232,24 @@ export class ManageClientsService { ); await connection.commit(); - 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."); } - if (P_CURSOR_rows.length > 0 && P_CURSOR_rows[0].ERRORMESG) { - throw new BadRequestException(P_CURSOR_rows[0].ERRORMESG); + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return { statusCode: 200, message: "Updated Successfully" }; + return { statusCode: 200, message: "Updated Successfully", ...fres[0] }; } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('UpdateClientContacts failed', error.stack || error); - throw new InternalServerException(); + handleError(error, ManageClientsService.name) } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } + await closeOracleDbConnection(connection, ManageClientsService.name) } }; @@ -498,91 +269,34 @@ export class ManageClientsService { 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: UpdateClientLocationsDTO = { ...newBody, ...reqBody }; let connection; - let P_CURSOR_rows: any = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } const result = await connection.execute( `BEGIN - MANAGEPREPARER_PKG.UpdateClientLocations( - :P_SPID, - :P_CLIENTLOCATIONID, - :P_LOCATIONNAME, - :P_ADDRESS1, - :P_ADDRESS2, - :P_CITY, - :P_STATE, - :P_ZIP, - :P_COUNTRY, - :P_USERID, - :P_CURSOR - ); - END;`, + MANAGEPREPARER_PKG.UpdateClientLocations( + :P_SPID, :P_CLIENTLOCATIONID, :P_LOCATIONNAME, :P_ADDRESS1, + :P_ADDRESS2, :P_CITY, :P_STATE, :P_ZIP, + :P_COUNTRY, :P_USERID, :P_CURSOR + ); + 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_LOCATIONNAME: { - val: finalBody.P_LOCATIONNAME ? finalBody.P_LOCATIONNAME : 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_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTLOCATIONID: { val: finalBody.P_CLIENTLOCATIONID, type: oracledb.DB_TYPE_NUMBER }, + P_LOCATIONNAME: { val: finalBody.P_LOCATIONNAME, 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, @@ -590,220 +304,28 @@ export class ManageClientsService { ); await connection.commit(); - 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."); } - if (P_CURSOR_rows.length > 0 && P_CURSOR_rows[0].ERRORMESG) { - throw new BadRequestException(P_CURSOR_rows[0].ERRORMESG); + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return { statusCode: 200, message: "Updated Successfully" }; + return { statusCode: 200, message: "Updated Successfully", ...fres[0] }; } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('UpdateClientLocations failed', error.stack || error); - throw new InternalServerException(); + handleError(error, ManageClientsService.name) } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } + await closeOracleDbConnection(connection, ManageClientsService.name) } }; - // CreateClientContactX = async (body: CreateClientContactsDTO) => { - // const newBody = { - // P_SPID: null, - // P_CLIENTID: null, - // p_contactstable: null, - // p_defcontactflag: 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: CreateClientContactsDTO = { - // ...newBody, - // ...reqBody, - // }; - - // let connection; - // let P_CURSOR_rows: any = []; - - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException('No DB Connected'); - // } - - // const CONTACTSTABLE = await connection.getDbObjectClass( - // 'CARNETSYS.CONTACTSTABLE', - // ); - - // // Check if CONTACTSTABLE is a constructor - // if (typeof CONTACTSTABLE !== 'function') { - // throw new InternalServerException('CONTACTSTABLE is not a constructor'); - // } - - // async function CREATECONTACTSTABLE_INSTANCE( - // connection, - // FirstName, - // LastName, - // MiddleInitial, - // Title, - // EmailAddress, - // PhoneNo, - // MobileNo, - // FaxNo, - // ) { - // const 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 = await connection.execute( - // `BEGIN - // MANAGEPREPARER_PKG.CreateClientContact( - // :P_SPID, - // :P_CLIENTID, - // :p_contactstable, - // :p_defcontactflag, - // :P_USERID, - // :P_CURSOR - // ); - // END;`, - // { - // P_SPID: { - // val: finalBody.P_SPID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_CLIENTID: { - // val: finalBody.P_CLIENTID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // p_contactstable: { - // val: CONTACTSTABLE_INSTANCE, - // type: oracledb.DB_TYPE_OBJECT, - // }, - // p_defcontactflag: { - // val: finalBody.p_defcontactflag, - // 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, - // }, - // ); - - // await connection.commit(); - - // 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 InternalServerException('No cursor returned from the stored procedure'); - // } - - // if (P_CURSOR_rows.length > 0 && P_CURSOR_rows[0].ERRORMESG) { - // throw new BadRequestException(P_CURSOR_rows[0].ERRORMESG); - // } - - // return { statusCode: 201, message: "Created Successfully" }; - - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('CreateClientContact 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 CreateClientContact(body: CreateClientContactsDTO) { const newBody = { P_SPID: null, @@ -815,16 +337,6 @@ export class ManageClientsService { 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: CreateClientContactsDTO = { ...newBody, ...reqBody }; @@ -833,62 +345,7 @@ export class ManageClientsService { try { connection = await this.oracleDBService.getConnection(); - const CONTACTSTABLE = await connection.getDbObjectClass( - 'CARNETSYS.CONTACTSTABLE', - ); - - // Check if CONTACTSTABLE is a constructor - if (typeof CONTACTSTABLE !== 'function') { - throw new InternalServerException('CONTACTSTABLE is not a constructor'); - } - - async function CREATECONTACTSTABLE_INSTANCE( - connection, - FirstName, - LastName, - MiddleInitial, - Title, - EmailAddress, - PhoneNo, - MobileNo, - FaxNo, - ) { - const 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: CONTACTSTABLE_ROW_DTO) => { - return await CREATECONTACTSTABLE_INSTANCE( - connection, - x.P_FIRSTNAME, - x.P_LASTNAME, - x.P_MIDDLEINITIAL, - x.P_TITLE, - x.P_EMAILADDRESS, - x.P_PHONENO, - x.P_MOBILENO, - x.P_FAXNO, - ); - }), - ) - : []; - - // Create an instance of GLTABLE - const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); + const CONTACTSTABLE_INSTANCE = await this.oracleService.get_CONTACTS_TABLE_INSTANCE(finalBody); const result = await connection.execute( `BEGIN @@ -915,7 +372,15 @@ export class ManageClientsService { throw new InternalServerException("Incomplete data received from the database."); } - return await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 201, message: "Created Successfully", ...fres[0] }; + } catch (error) { handleError(error, ManageClientsService.name) } finally { @@ -933,119 +398,30 @@ export class ManageClientsService { 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: CreateClientLocationsDTO = { - ...newBody, - ...reqBody, - }; + const finalBody: CreateClientLocationsDTO = { ...newBody, ...reqBody, }; let connection; - let P_CURSOR_rows: any = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } - const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass( - 'CARNETSYS.CLIENTLOCADDRESSTABLE', - ); - - if (typeof CLIENTLOCADDRESSTABLE !== 'function') { - throw new Error('CLIENTLOCADDRESSTABLE is not a constructor'); - } - - async function CREATECLIENTLOCADDRESSTABLE_INSTANCE( - connection, - Nameof, - Address1, - Address2, - City, - State, - Zip, - Country, - ) { - const result = await connection.execute( - `SELECT CARNETSYS.CLIENTLOCADDRESSARRAY(:Nameof, :Address1, :Address2, :City, :State, :Zip, :Country) FROM dual`, - { - Nameof, - Address1, - Address2, - City, - State, - Zip, - Country, - }, - ); - return result.rows[0][0]; - } - - const CLIENTLOCADDRESSARRAY = finalBody.P_CLIENTLOCADDRESSTABLE - ? await Promise.all( - finalBody.P_CLIENTLOCADDRESSTABLE.map( - async (x: CLIENTLOCADDRESSTABLE_ROW_DTO) => { - return await CREATECLIENTLOCADDRESSTABLE_INSTANCE( - connection, - x.P_NAMEOF, - x.P_ADDRESS1, - x.P_ADDRESS2, - x.P_CITY, - x.P_CITY, - x.P_ZIP, - x.P_COUNTRY, - ); - }, - ), - ) - : []; - - const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE( - CLIENTLOCADDRESSARRAY, - ); + const CLIENTLOCADDRESSTABLE_INSTANCE = await this.oracleService.get_CLIENTLOCADDRESS_TABLE_INSTANCE(finalBody); const result = await connection.execute( `BEGIN - MANAGEPREPARER_PKG.CreateClientLocation( - :P_SPID, - :P_CLIENTID, - :p_ClientLocAddressTable, - :P_USERID, - :P_CURSOR - ); - END;`, + MANAGEPREPARER_PKG.CreateClientLocation( + :P_SPID, :P_CLIENTID, :P_CLIENTLOCADDRESSTABLE, :P_USERID, + :P_CURSOR + ); + END;`, { - P_SPID: { - val: finalBody.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CLIENTID: { - val: finalBody.P_CLIENTID, - type: oracledb.DB_TYPE_NUMBER, - }, - p_clientlocaddresstable: { - val: CLIENTLOCADDRESSTABLE_INSTANCE, - type: oracledb.DB_TYPE_OBJECT, - }, - P_USERID: { - val: finalBody.P_USERID, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CURSOR: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - } + P_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTID: { val: finalBody.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER }, + p_clientlocaddresstable: { val: CLIENTLOCADDRESSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, + 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, @@ -1054,139 +430,162 @@ export class ManageClientsService { await connection.commit(); - 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."); } - if (P_CURSOR_rows.length > 0 && P_CURSOR_rows[0].ERRORMESG) { - throw new BadRequestException(P_CURSOR_rows[0].ERRORMESG); + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) } - return { statusCode: 201, message: "Created Successfully" }; + return { statusCode: 201, message: "Created Successfully", ...fres[0] }; } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('CreateClientLocation failed', error.stack || error); - throw new InternalServerException(); + handleError(error, ManageClientsService.name) } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } + await closeOracleDbConnection(connection, ManageClientsService.name) } }; GetPreparers = async (body: GetPreparersDTO) => { + + const newBody = { + P_SPID: null, + P_NAME: null, + P_LOOKUPCODE: null, + P_CITY: null, + P_STATE: null, + P_STATUS: null, + P_MAINCURSOR: null + } + + const reqBody = JSON.parse(JSON.stringify(body)); + + setEmptyStringsToNull(reqBody); + + const finalBody: GetPreparersDTO = { ...newBody, ...reqBody, }; + let connection; - let p_maincursor_rows = []; - // let p_contactscursor_rows = []; - // let p_locationcursor_rows = []; try { connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new InternalServerException(); - } const result = await connection.execute( `BEGIN - MANAGEPREPARER_PKG.GetPreparers( - :P_SPID, - :P_NAME, - :P_LOOKUPCODE, - :P_CITY, - :P_STATE, - :P_STATUS, - :p_maincursor - ); - END;`, + MANAGEPREPARER_PKG.GetPreparers( + :P_SPID, :P_NAME, :P_LOOKUPCODE, :P_CITY, + :P_STATE, :P_STATUS, :P_MAINCURSOR + ); + END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_NAME: { - val: body.P_NAME, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_LOOKUPCODE: { - val: body.P_LOOKUPCODE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_CITY: { - val: body.P_CITY, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_STATE: { - val: body.P_STATE, - type: oracledb.DB_TYPE_NVARCHAR, - }, - P_STATUS: { - val: body.P_STATUS, - type: oracledb.DB_TYPE_NVARCHAR, - }, - p_maincursor: { - type: oracledb.CURSOR, - dir: oracledb.BIND_OUT, - } + P_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_NAME: { val: finalBody.P_NAME, type: oracledb.DB_TYPE_NVARCHAR }, + P_LOOKUPCODE: { val: finalBody.P_LOOKUPCODE, 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_STATUS: { val: finalBody.P_STATUS, type: oracledb.DB_TYPE_NVARCHAR }, + P_MAINCURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT, }, ); - if (result.outBinds && result.outBinds.p_maincursor) { - const cursor = result.outBinds.p_maincursor; - let rowsBatch; - - do { - rowsBatch = await cursor.getRows(100); - p_maincursor_rows = p_maincursor_rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); + const outBinds: any = result.outBinds; + if (!outBinds?.P_MAINCURSOR) { + 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_maincursor_rows; + return await fetchCursor(outBinds.P_MAINCURSOR, ManageClientsService.name); } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('GetPreparers failed', error.stack || error); - throw new InternalServerException(); + handleError(error, ManageClientsService.name) } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } + await closeOracleDbConnection(connection, ManageClientsService.name) } }; - GetPreparerByClientid = async ( - body: GetPreparerByClientidContactsByClientidLocByClientidDTO, - ) => { + GetPreparerByClientid = async (body: GetClientDTO) => { + let connection; + + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + MANAGEPREPARER_PKG.GetPreparerByClientid( + :P_SPID, :P_CLIENTID, :P_CURSOR + ); + END;`, + { + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTID: { val: body.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + 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 await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + } catch (error) { + handleError(error, ManageClientsService.name) + } finally { + await closeOracleDbConnection(connection, ManageClientsService.name) + } + }; + + GetPreparerContactsByClientid = async (body: GetClientDTO) => { + let connection; + + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + MANAGEPREPARER_PKG.GetPreparerContactsByClientid( + :P_SPID, :P_CLIENTID, :P_CURSOR + ); + END;`, + { + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTID: { val: body.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + 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 await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + } catch (error) { + handleError(error, ManageClientsService.name) + } finally { + await closeOracleDbConnection(connection, ManageClientsService.name) + } + }; + + GetPreparerLocByClientid = async (body: GetClientDTO) => { let connection; - let P_CURSOR_rows: any = []; try { connection = await this.oracleDBService.getConnection(); @@ -1196,200 +595,32 @@ export class ManageClientsService { const result = await connection.execute( `BEGIN - MANAGEPREPARER_PKG.GetPreparerByClientid( - :P_SPID, - :P_CLIENTID, - :P_CURSOR - ); - END;`, + MANAGEPREPARER_PKG.GetPreparerLocByClientid( + :P_SPID, :P_CLIENTID, :P_CURSOR + ); + END;`, { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CLIENTID: { - val: body.P_CLIENTID, - 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_CLIENTID: { val: body.P_CLIENTID, 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_rows; + return await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('GetPreparerByClientid failed', error.stack || error); - throw new InternalServerException(); + handleError(error, ManageClientsService.name) } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } - } - }; - - GetPreparerContactsByClientid = async ( - body: GetPreparerByClientidContactsByClientidLocByClientidDTO, - ) => { - let connection; - let P_CURSOR_rows = []; - - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } - - const result = await connection.execute( - `BEGIN - MANAGEPREPARER_PKG.GetPreparerContactsByClientid( - :P_SPID, - :P_CLIENTID, - :P_CURSOR - ); - END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CLIENTID: { - val: body.P_CLIENTID, - 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(); - } - - return P_CURSOR_rows; - } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('GetPreparerContactsByClientid 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); - } - } - } - }; - - GetPreparerLocByClientid = async ( - body: GetPreparerByClientidContactsByClientidLocByClientidDTO, - ) => { - let connection; - let P_CURSOR_rows = []; - - try { - connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new Error('No DB Connected'); - } - - const result = await connection.execute( - `BEGIN - MANAGEPREPARER_PKG.GetPreparerLocByClientid( - :P_SPID, - :P_CLIENTID, - :P_CURSOR - ); - END;`, - { - P_SPID: { - val: body.P_SPID, - type: oracledb.DB_TYPE_NUMBER, - }, - P_CLIENTID: { - val: body.P_CLIENTID, - 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(); - } - - return P_CURSOR_rows; - } catch (error) { - if (error instanceof BadRequestException) { - this.logger.warn(error.message); - throw error; - } - this.logger.error('GetPreparerLocByClientid 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); - } - } + await closeOracleDbConnection(connection, ManageClientsService.name) } }; } diff --git a/src/oracle/manage-holders/manage-holders.controller.ts b/src/oracle/manage-holders/manage-holders.controller.ts index 5461cf4..2beb563 100644 --- a/src/oracle/manage-holders/manage-holders.controller.ts +++ b/src/oracle/manage-holders/manage-holders.controller.ts @@ -25,6 +25,7 @@ export class ManageHoldersController { @Post('/CreateHolderData') CreateHolders(@Body() body: CreateHoldersDTO) { return this.manageHoldersService.CreateHolders(body); + // return this.manageHoldersService.CreateHoldersX(); // return {message:"Request received.."} } diff --git a/src/oracle/manage-holders/manage-holders.service.ts b/src/oracle/manage-holders/manage-holders.service.ts index cf5372a..ef95b28 100644 --- a/src/oracle/manage-holders/manage-holders.service.ts +++ b/src/oracle/manage-holders/manage-holders.service.ts @@ -9,12 +9,16 @@ import { CONTACTSTABLE_ROW_DTO, CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO, HolderContactActivateOrInactivateDTO, UpdateHolderContactDTO, UpdateHolderDTO } from 'src/dto/property.dto'; +import { OracleService } from '../oracle.service'; @Injectable() export class ManageHoldersService { private readonly logger = new Logger(ManageHoldersService.name); - constructor(private readonly oracleDBService: OracleDBService) { } + constructor( + private readonly oracleDBService: OracleDBService, + private readonly oracleService: OracleService + ) { } // CreateHoldersX = async (body: CreateHoldersDTO) => { // const newBody = { @@ -336,164 +340,38 @@ export class ManageHoldersService { connection = await this.oracleDBService.getConnection(); - 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: CONTACTSTABLE_ROW_DTO) => { - return await CREATECONTACTSTABLE_INSTANCE( - connection, - x.P_FIRSTNAME, - x.P_LASTNAME, - x.P_MIDDLEINITIAL, - x.P_TITLE, - x.P_EMAILADDRESS, - x.P_PHONENO, - x.P_MOBILENO, - x.P_FAXNO, - ); - }), - ) - : []; - - // Create an instance of GLTABLE - const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); + const CONTACTSTABLE_INSTANCE = await this.oracleService.get_CONTACTS_TABLE_INSTANCE(finalBody) const 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;`, + 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, - }, + P_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTLOCATIONID: { val: finalBody.P_CLIENTLOCATIONID, 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_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: 'CARNETSYS.CONTACTSTABLE' }, + P_HOLDERCURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }, + P_HOLDERCONTACTCURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); diff --git a/src/oracle/oracle.service.ts b/src/oracle/oracle.service.ts index 3876f52..c0f4334 100644 --- a/src/oracle/oracle.service.ts +++ b/src/oracle/oracle.service.ts @@ -1,6 +1,6 @@ import { Injectable, Logger } from "@nestjs/common"; import { OracleDBService } from "src/db/db.service"; -import { COUNTRYTABLE_DTO, COUNTRYTABLE_ROW_DTO, GLTABLE_DTO, GLTABLE_ROW_DTO } from "src/dto/property.dto"; +import { CLIENTLOCADDRESSTABLE_ROW_DTO, CONTACTSTABLE_ROW_DTO, COUNTRYTABLE_DTO, COUNTRYTABLE_ROW_DTO, GLTABLE_DTO, GLTABLE_ROW_DTO } from "src/dto/property.dto"; import { InternalServerException } from "src/exceptions/internalServerError.exception"; import { closeOracleDbConnection, handleError } from "src/utils/helper"; @@ -118,4 +118,129 @@ export class OracleService { await closeOracleDbConnection(connection, OracleService.name) } } + + async get_CONTACTS_TABLE_INSTANCE(finalBody: any) { + + // P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: 'CARNETSYS.CONTACTSTABLE' } + + // P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT } + // this is working fine for CreateCientContact + + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const CONTACTSTABLE = await connection.getDbObjectClass('CARNETSYS.CONTACTSTABLE'); + + 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 = 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: CONTACTSTABLE_ROW_DTO) => { + return await CREATECONTACTSTABLE_INSTANCE( + connection, + x.P_FIRSTNAME, + x.P_LASTNAME, + x.P_MIDDLEINITIAL, + x.P_TITLE, + x.P_EMAILADDRESS, + x.P_PHONENO, + x.P_MOBILENO, + x.P_FAXNO, + ); + }), + ) + : []; + + const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); + + return CONTACTSTABLE_INSTANCE; + + } catch (error) { + throw new Error("Error occured completing this process") + } finally { + await closeOracleDbConnection(connection, OracleService.name) + } + } + + async get_CLIENTLOCADDRESS_TABLE_INSTANCE(finalBody: any) { + + // P_CLIENTLOCADDRESSTABLE: { val: CLIENTLOCADDRESSTABLE_INSTANCE, type: 'CARNETSYS.CLIENTLOCADDRESSTABLE' } + // P_CLIENTLOCADDRESSTABLE: { val: CLIENTLOCADDRESSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT } + + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSTABLE'); + + if (typeof CLIENTLOCADDRESSTABLE !== 'function') { + throw new Error('CLIENTLOCADDRESSTABLE is not a constructor'); + } + + async function CREATECLIENTLOCADDRESSTABLE_INSTANCE( + connection, Nameof, Address1, Address2, + City, State, Zip, Country, + ) { + const result = await connection.execute( + `SELECT CARNETSYS.CLIENTLOCADDRESSARRAY( + :Nameof, :Address1, :Address2, :City, + :State, :Zip, :Country + ) FROM dual`, + { + Nameof, Address1, Address2, City, + State, Zip, Country, + }, + ); + return result.rows?.[0]?.[0] ?? []; + } + + const CLIENTLOCADDRESSARRAY = finalBody.P_CLIENTLOCADDRESSTABLE + ? await Promise.all( + finalBody.P_CLIENTLOCADDRESSTABLE.map( + async (x: CLIENTLOCADDRESSTABLE_ROW_DTO) => { + return await CREATECLIENTLOCADDRESSTABLE_INSTANCE( + connection, + x.P_NAMEOF, + x.P_ADDRESS1, + x.P_ADDRESS2, + x.P_CITY, + x.P_STATE, + x.P_ZIP, + x.P_COUNTRY, + ); + }, + ), + ) + : []; + + const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE(CLIENTLOCADDRESSARRAY); + + return CLIENTLOCADDRESSTABLE_INSTANCE; + + } catch (error) { + throw new Error("Error occured completing this process") + } finally { + await closeOracleDbConnection(connection, OracleService.name) + } + } } \ No newline at end of file diff --git a/src/oracle/param-table/param-table.service.ts b/src/oracle/param-table/param-table.service.ts index 9afac1d..b06db8e 100644 --- a/src/oracle/param-table/param-table.service.ts +++ b/src/oracle/param-table/param-table.service.ts @@ -17,80 +17,6 @@ export class ParamTableService { constructor(private readonly oracleDBService: OracleDBService) { } - // async GETPARAMVALUESX(body: getParamValuesDTO) { - // const finalBody = { - // P_SPID: body.P_SPID === 0 ? body.P_SPID : body.P_SPID ? body.P_SPID : null, - // P_PARAMTYPE: body.P_PARAMTYPE ? body.P_PARAMTYPE : null, - // }; - - // let connection; - // let rows = []; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // MANAGEPARAMTABLE_PKG.GETPARAMVALUES(:P_SPID,:P_PARAMTYPE,:P_CURSOR); - // END;`, - // { - // P_SPID: { - // val: finalBody.P_SPID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_PARAMTYPE: { - // val: finalBody.P_PARAMTYPE, - // type: oracledb.DB_TYPE_NVARCHAR, - // }, - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - - // if (result.outBinds && result.outBinds.P_CURSOR) { - // const cursor = result.outBinds.P_CURSOR; - // let rowsBatch; - - // do { - // rowsBatch = await cursor.getRows(100); - // rows = rows.concat(rowsBatch); - // } while (rowsBatch.length > 0); - - // await cursor.close(); - // } else { - // throw new BadRequestException(); - // } - - // return rows; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // else if (error.message === "NJS-107: invalid cursor") { - // this.logger.warn(error.message); - // throw new BadRequestException(); - // } - // this.logger.error('GETPARAMVALUES 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 GETPARAMVALUES(body: getParamValuesDTO) { const finalBody = { P_SPID: body.P_SPID === 0 ? body.P_SPID : body.P_SPID ? body.P_SPID : null, @@ -137,65 +63,6 @@ export class ParamTableService { } } - // async CREATETABLERECORDX(body: CreateTableRecordDTO) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // MANAGEPARAMTABLE_PKG.CREATETABLERECORD(:P_USERID,:P_TABLEFULLDESC,:P_CURSOR); - // END;`, - // { - // P_TABLEFULLDESC: { - // val: body.P_TABLEFULLDESC, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // 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, - // }, - // ); - // await connection.commit(); - - // const fres = await result.outBinds.P_CURSOR.getRows(); - - // if (fres.length > 0 && fres[0].ERRORMESG) { - // this.logger.warn(fres[0].ERRORMESG); - // throw new BadRequestException(fres[0].ERRORMESG) - // } - - // return { statusCode: 201, message: "Createdted Successfully", ...fres[0] }; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('CREATETABLERECORD failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } - async CREATETABLERECORD(body: CreateTableRecordDTO) { let connection; @@ -238,115 +105,6 @@ export class ParamTableService { } } - // async CREATEPARAMRECORDX(body: CreateParamRecordDTO) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // MANAGEPARAMTABLE_PKG.CREATEPARAMRECORD( - // :P_SPID, - // :P_PARAMTYPE, - // :P_PARAMDESC, - // :P_PARAMVALUE, - // :P_ADDLPARAMVALUE1, - // :P_ADDLPARAMVALUE2, - // :P_ADDLPARAMVALUE3, - // :P_ADDLPARAMVALUE4, - // :P_ADDLPARAMVALUE5, - // :P_SORTSEQ, - // :P_USERID, - // :P_CURSOR); - // END;`, - // { - // P_SPID: { - // val: body.P_SPID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_PARAMTYPE: { - // val: body.P_PARAMTYPE, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_PARAMDESC: { - // val: body.P_PARAMDESC, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_PARAMVALUE: { - // val: body.P_PARAMVALUE, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE1: { - // val: body.P_ADDLPARAMVALUE1, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE2: { - // val: body.P_ADDLPARAMVALUE2, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE3: { - // val: body.P_ADDLPARAMVALUE3, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE4: { - // val: body.P_ADDLPARAMVALUE4, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE5: { - // val: body.P_ADDLPARAMVALUE5, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_SORTSEQ: { - // val: body.P_SORTSEQ, - // 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, - // }, - // ); - // await connection.commit(); - - // const fres = await result.outBinds.P_CURSOR.getRows(); - - // if (fres.length > 0 && fres[0].ERRORMESG) { - // this.logger.warn(fres[0].ERRORMESG); - // throw new BadRequestException(fres[0].ERRORMESG) - // } - - // return { statusCode: 201, message: "Createdted Successfully", ...fres[0] }; - // } catch (error) { - // if (error instanceof BadRequestException) { - // throw error; - // } - // else if (error.message === "NJS-107: invalid cursor") { - // throw new BadRequestException(); - // } - // this.logger.error('CREATEPARAMRECORD failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } - async CREATEPARAMRECORD(body: CreateParamRecordDTO) { let connection; @@ -410,108 +168,6 @@ export class ParamTableService { } } - // async UPDATEPARAMRECORDX(body: UpdateParamRecordDTO) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // MANAGEPARAMTABLE_PKG.UPDATEPARAMRECORD( - // :P_SPID, - // :P_PARAMID, - // :P_PARAMDESC, - // :P_ADDLPARAMVALUE1, - // :P_ADDLPARAMVALUE2, - // :P_ADDLPARAMVALUE3, - // :P_ADDLPARAMVALUE4, - // :P_ADDLPARAMVALUE5, - // :P_SORTSEQ, - // :P_USERID, - // :P_CURSOR); - // END;`, - // { - // P_SPID: { - // val: body.P_SPID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_PARAMID: { - // val: body.P_PARAMID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_PARAMDESC: { - // val: body.P_PARAMDESC, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE1: { - // val: body.P_ADDLPARAMVALUE1, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE2: { - // val: body.P_ADDLPARAMVALUE2, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE3: { - // val: body.P_ADDLPARAMVALUE3, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE4: { - // val: body.P_ADDLPARAMVALUE4, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDLPARAMVALUE5: { - // val: body.P_ADDLPARAMVALUE5, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_SORTSEQ: { - // val: body.P_SORTSEQ, - // 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, - // }, - // ); - // await connection.commit(); - - // const fres = await result.outBinds.P_CURSOR.getRows(); - - // if (fres.length > 0 && fres[0].ERRORMESG) { - // this.logger.warn(fres[0].ERRORMESG); - // throw new BadRequestException(fres[0].ERRORMESG) - // } - - // return { statusCode: 200, message: "Updated Successfully", ...fres[0] }; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('UPDATEPARAMRECORD failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } - async UPDATEPARAMRECORD(body: UpdateParamRecordDTO) { let connection; @@ -573,48 +229,6 @@ export class ParamTableService { } } - // async INACTIVATEPARAMRECORDX(body: ActivateOrInactivateParamRecordDTO) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // MANAGEPARAMTABLE_PKG.INACTIVATEPARAMRECORD( - // :P_PARAMID, - // :P_USERID); - // END;`, - // { - // P_PARAMID: { - // val: body.P_PARAMID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_USERID: { - // val: body.P_USERID, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // }, - // ); - // await connection.commit(); - - // return { statusCode: 200, message: 'Inactivated Successfully' }; - // } catch (error) { - // this.logger.error('INACTIVATEPARAMRECORD failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } - async INACTIVATEPARAMRECORD(body: ActivateOrInactivateParamRecordDTO) { let connection; @@ -649,48 +263,6 @@ export class ParamTableService { } } - // async REACTIVATEPARAMRECORDX(body: ActivateOrInactivateParamRecordDTO) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // MANAGEPARAMTABLE_PKG.REACTIVATEPARAMRECORD( - // :P_PARAMID, - // :P_USERID); - // END;`, - // { - // P_PARAMID: { - // val: body.P_PARAMID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_USERID: { - // val: body.P_USERID, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // }, - // ); - // await connection.commit(); - - // return { statusCode: 200, message: 'Reactivated Successfully' }; - // } catch (error) { - // this.logger.error('REACTIVATEPARAMRECORD failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } - async REACTIVATEPARAMRECORD(body: ActivateOrInactivateParamRecordDTO) { let connection; 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 302b3df..8f886ce 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 @@ -140,67 +140,43 @@ export class CarnetSequenceService { async getCarnetSequenceX(body: SPID_DTO) { let connection; - let rows = []; try { - // Connect to the Oracle database using oracledb + connection = await this.oracleDBService.getConnection(); - if (!connection) { - throw new InternalServerException(); - } const result = await connection.execute( `BEGIN USCIB_Managed_Pkg.GetCarnetSequence(:P_SPID,:P_CURSOR); END;`, { - P_SPID: { - val: body.P_SPID, - 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_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); - rows = rows.concat(rowsBatch); - } while (rowsBatch.length > 0); - - await cursor.close(); - } else { - throw new BadRequestException(); + const outBinds = 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; + let fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetSequenceService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + 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('getCarnetSequence failed', error.stack || error); - throw new InternalServerException(); + handleError(error, CarnetSequenceService.name) } finally { - if (connection) { - try { - await connection.close(); - } catch (closeErr) { - this.logger.error('Failed to close DB connection', closeErr); - } - } + await closeOracleDbConnection(connection, CarnetSequenceService.name) } } diff --git a/src/oracle/uscib-managed-sp/region/region.service.ts b/src/oracle/uscib-managed-sp/region/region.service.ts index b6627fd..c6ea636 100644 --- a/src/oracle/uscib-managed-sp/region/region.service.ts +++ b/src/oracle/uscib-managed-sp/region/region.service.ts @@ -13,64 +13,6 @@ export class RegionService { constructor(private readonly oracleDBService: OracleDBService) { } - // async insertRegionsX(body: InsertRegionsDto) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.InsertNewRegion(:P_REGION,:P_NAME,:P_CURSOR); - // END;`, - // { - // P_REGION: { - // val: body.P_REGION, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_NAME: { - // val: body.P_NAME, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - - // await connection.commit(); - - // const fres = await result.outBinds.P_CURSOR.getRows(); - - // if (fres.length > 0 && fres[0].ERRORMESG) { - // this.logger.warn(fres[0].ERRORMESG); - // throw new BadRequestException(fres[0].ERRORMESG) - // } - - // return { statusCode: 201, message: "Createdted Successfully", ...fres[0] }; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('insertRegions failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } async insertRegions(body: InsertRegionsDto) { let connection; @@ -113,65 +55,6 @@ export class RegionService { } } - // async updateRegionsX(body: UpdateRegionDto) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.UpdateRegion(:P_REGIONID,:P_NAME,:P_CURSOR); - // END;`, - // { - // P_REGIONID: { - // val: body.P_REGIONID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_NAME: { - // val: body.P_NAME, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - - // await connection.commit(); - - // const fres = await result.outBinds.P_CURSOR.getRows(); - - // if (fres.length > 0 && fres[0].ERRORMESG) { - // this.logger.warn(fres[0].ERRORMESG); - // throw new BadRequestException(fres[0].ERRORMESG) - // } - - // return { statusCode: 200, message: "Updated Successfully", ...fres[0] }; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('updateRegions failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } - async updateRegions(body: UpdateRegionDto) { let connection; try { @@ -211,68 +94,6 @@ export class RegionService { await closeOracleDbConnection(connection, RegionService.name) } } - - // async getRegionsX() { - // let connection; - // let rows = []; - // try { - - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException() - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.GetRegions(:P_CURSOR); - // END;`, - // { - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - - // if (result.outBinds && result.outBinds.P_CURSOR) { - // const cursor = result.outBinds.P_CURSOR; - // let rowsBatch; - - // do { - // rowsBatch = await cursor.getRows(100); - // rows = rows.concat(rowsBatch); - // } while (rowsBatch.length > 0); - - // await cursor.close(); - // } else { - // throw new BadRequestException(); - // } - - // return rows; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // else if (error.message === "NJS-107: invalid cursor") { - // this.logger.warn(error.message); - // throw new BadRequestException(); - // } - // this.logger.error('GETBASICFEERATES 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 getRegions() { let connection; diff --git a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts index 30e2b6f..d88710e 100644 --- a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts +++ b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts @@ -5,10 +5,11 @@ import { BadRequestException } from 'src/exceptions/badRequest.exception'; import { InternalServerException } from 'src/exceptions/internalServerError.exception'; import { closeOracleDbConnection, fetchCursor, handleError } from 'src/utils/helper'; -import { SPID_DTO, +import { + SPID_DTO, SP_CONTACTID_DTO, - InsertSPContactsDTO,UpdateSPContactsDTO - } from 'src/dto/property.dto'; + InsertSPContactsDTO, UpdateSPContactsDTO +} from 'src/dto/property.dto'; @Injectable() export class SpContactsService { @@ -16,111 +17,6 @@ export class SpContactsService { constructor(private readonly oracleDBService: OracleDBService) { } - // async insertSPContactsX(body: InsertSPContactsDTO) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.InsertSPContacts( - // :P_SPID, - // :P_DEFCONTACTFLAG, - // :P_FIRSTNAME, - // :P_LASTNAME, - // :P_MIDDLEINITIAL, - // :P_TITLE, - // :P_PHONENO, - // :P_MOBILENO, - // :P_FAXNO, - // :P_EMAILADDRESS, - // :P_USER_ID, - // :P_CURSOR); - // END;`, - // { - // P_SPID: { - // val: body.P_SPID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_DEFCONTACTFLAG: { - // val: body.P_DEFCONTACTFLAG, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_FIRSTNAME: { - // val: body.P_FIRSTNAME, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_LASTNAME: { - // val: body.P_LASTNAME, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_MIDDLEINITIAL: { - // val: body.P_MIDDLEINITIAL, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_TITLE: { - // val: body.P_TITLE, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_PHONENO: { - // val: body.P_PHONENO, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_MOBILENO: { - // val: body.P_MOBILENO, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_FAXNO: { - // val: body.P_FAXNO, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_EMAILADDRESS: { - // val: body.P_EMAILADDRESS, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_USER_ID: { - // val: body.P_USER_ID, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - - // await connection.commit(); - - // const fres = await result.outBinds.P_CURSOR.getRows(); - - // if (fres.length > 0 && fres[0].ERRORMESG) { - // this.logger.warn(fres[0].ERRORMESG); - // throw new BadRequestException(fres[0].ERRORMESG) - // } - - // return { statusCode: 201, message: "Createdted Successfully", ...fres[0] }; - // } catch (error) { - // if (error instanceof BadRequestException) { - // throw error; - // } - // this.logger.error('insertSPContacts failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } async insertSPContacts(body: InsertSPContactsDTO) { @@ -131,17 +27,9 @@ export class SpContactsService { const result = await connection.execute( `BEGIN USCIB_Managed_Pkg.InsertSPContacts( - :P_SPID, - :P_DEFCONTACTFLAG, - :P_FIRSTNAME, - :P_LASTNAME, - :P_MIDDLEINITIAL, - :P_TITLE, - :P_PHONENO, - :P_MOBILENO, - :P_FAXNO, - :P_EMAILADDRESS, - :P_USER_ID, + :P_SPID, :P_DEFCONTACTFLAG, :P_FIRSTNAME, :P_LASTNAME, + :P_MIDDLEINITIAL, :P_TITLE, :P_PHONENO, :P_MOBILENO, + :P_FAXNO, :P_EMAILADDRESS, :P_USER_ID, :P_CURSOR); END;`, { @@ -185,43 +73,6 @@ export class SpContactsService { } } - // async setSPDefaultcontactX(body: SP_CONTACTID_DTO) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.SetDefaultContact(:P_SPCONTACTID); - // END;`, - // { - // P_SPCONTACTID: { - // val: body.P_SPCONTACTID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // }, - // ); - - // await connection.commit(); - - // return { statusCode: 200, message: 'Default contact was added successfully for SP' }; - // } catch (error) { - // this.logger.error('setSPDefaultcontact failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } - async setSPDefaultcontact(body: SP_CONTACTID_DTO) { let connection; @@ -255,108 +106,6 @@ export class SpContactsService { } } - // async updateSPContactsX(body: UpdateSPContactsDTO) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.UpdateSPContacts( - // :P_SPCONTACTID, - // :P_FIRSTNAME, - // :P_LASTNAME, - // :P_MIDDLEINITIAL, - // :P_TITLE, - // :P_PHONENO, - // :P_MOBILENO, - // :P_FAXNO, - // :P_EMAILADDRESS, - // :P_USER_ID, - // :P_CURSOR); - // END;`, - // { - // P_SPCONTACTID: { - // val: body.P_SPCONTACTID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // P_FIRSTNAME: { - // val: body.P_FIRSTNAME, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_LASTNAME: { - // val: body.P_LASTNAME, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_MIDDLEINITIAL: { - // val: body.P_MIDDLEINITIAL, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_TITLE: { - // val: body.P_TITLE, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_PHONENO: { - // val: body.P_PHONENO, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_MOBILENO: { - // val: body.P_MOBILENO, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_FAXNO: { - // val: body.P_FAXNO, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_EMAILADDRESS: { - // val: body.P_EMAILADDRESS, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_USER_ID: { - // val: body.P_USER_ID, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - - // await connection.commit(); - - // const fres = await result.outBinds.P_CURSOR.getRows(); - - // if (fres.length > 0 && fres[0].ERRORMESG) { - // this.logger.warn(fres[0].ERRORMESG); - // throw new BadRequestException(fres[0].ERRORMESG) - // } - - // return { statusCode: 200, message: "Updated Successfully" }; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('updateSPContacts 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 updateSPContacts(body: UpdateSPContactsDTO) { let connection; @@ -366,17 +115,9 @@ export class SpContactsService { const result = await connection.execute( `BEGIN USCIB_Managed_Pkg.UpdateSPContacts( - :P_SPCONTACTID, - :P_FIRSTNAME, - :P_LASTNAME, - :P_MIDDLEINITIAL, - :P_TITLE, - :P_PHONENO, - :P_MOBILENO, - :P_FAXNO, - :P_EMAILADDRESS, - :P_USER_ID, - :P_CURSOR); + :P_SPCONTACTID, :P_FIRSTNAME, :P_LASTNAME, :P_MIDDLEINITIAL, + :P_TITLE, :P_PHONENO, :P_MOBILENO, :P_FAXNO, + :P_EMAILADDRESS, :P_USER_ID, :P_CURSOR); END;`, { P_SPCONTACTID: { val: body.P_SPCONTACTID, type: oracledb.DB_TYPE_NUMBER }, @@ -418,43 +159,6 @@ export class SpContactsService { } } - // async inactivateSPContactX(body: SP_CONTACTID_DTO) { - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.InActivateSPContacts(:P_SPCONTACTID); - // END;`, - // { - // P_SPCONTACTID: { - // val: body.P_SPCONTACTID, - // type: oracledb.DB_TYPE_NUMBER, - // }, - // }, - // ); - - // await connection.commit(); - - // return { statusCode: 200, message: 'Inactivated SP contact successfully' }; - // } catch (error) { - // this.logger.error('inactivateSPContact failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } - async inactivateSPContact(body: SP_CONTACTID_DTO) { let connection; @@ -488,63 +192,6 @@ export class SpContactsService { } } - // async getSPDefaultcontactsX(body: SPID_DTO) { - // let connection; - // let rows = []; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.GetSPDefaultContacts(:P_SPID,:P_CURSOR); - // END;`, - // { - // P_SPID: { - // val: body.P_SPID, - // 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); - // rows = rows.concat(rowsBatch); - // } while (rowsBatch.length > 0); - - // await cursor.close(); - // } else { - // throw new BadRequestException(); - // } - - // return rows; - // } catch (error) { - // this.logger.error('getSPDefaultcontacts 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 getSPDefaultcontacts(body: SPID_DTO) { let connection; @@ -553,7 +200,7 @@ export class SpContactsService { const result = await connection.execute( `BEGIN - USCIB_Managed_Pkg.GetSPDefaultContacts(:P_SPID,:P_CURSOR); + USCIB_Managed_Pkg.GetSPDefaultContacts(:P_SPID, :P_CURSOR); END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, @@ -579,64 +226,6 @@ export class SpContactsService { } } - // async getSPAllContactsX(body: SPID_DTO) { - - // let connection; - // let rows = []; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.GetSPAllContacts(:P_SPID,:P_CURSOR); - // END;`, - // { - // P_SPID: { - // val: body.P_SPID, - // 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); - // rows = rows.concat(rowsBatch); - // } while (rowsBatch.length > 0); - - // await cursor.close(); - // } else { - // throw new BadRequestException(); - // } - - // return rows; - // } catch (error) { - // this.logger.error('getSPAllContacts 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 getSPAllContacts(body: SPID_DTO) { let connection; @@ -645,7 +234,7 @@ export class SpContactsService { const result = await connection.execute( `BEGIN - USCIB_Managed_Pkg.GetSPAllContacts(:P_SPID,:P_CURSOR); + USCIB_Managed_Pkg.GetSPAllContacts(:P_SPID, :P_CURSOR); END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, diff --git a/src/oracle/uscib-managed-sp/sp/sp.service.ts b/src/oracle/uscib-managed-sp/sp/sp.service.ts index f8e72e4..c0bd25c 100644 --- a/src/oracle/uscib-managed-sp/sp/sp.service.ts +++ b/src/oracle/uscib-managed-sp/sp/sp.service.ts @@ -16,87 +16,6 @@ export class SpService { constructor(private readonly oracleDBService: OracleDBService) { } - // async insertNewServiceProviderX(body: InsertNewServiceProviderDTO) { - - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.InsertNewSP( - // :P_NAME, - // :P_LOOKUPCODE, - // :P_ADDRESS1, - // :P_ADDRESS2, - // :P_CITY, - // :P_STATE, - // :P_ZIP, - // :P_COUNTRY, - // :P_ISSUINGREGION, - // :P_REPLACEMENTREGION, - // :P_BONDSURETY, - // :P_CARGOPOLICYNO, - // :P_CARGOSURETY, - // :P_USER_ID, - // :P_NOTES, - // :P_FILEIDS, - // :P_CURSOR); - // END;`, - // { - // P_NAME: { val: body.P_NAME, type: oracledb.DB_TYPE_VARCHAR }, - // P_LOOKUPCODE: { val: body.P_LOOKUPCODE, type: oracledb.DB_TYPE_VARCHAR }, - // P_ADDRESS1: { val: body.P_ADDRESS1, type: oracledb.DB_TYPE_VARCHAR }, - // P_ADDRESS2: { val: body.P_ADDRESS2, type: oracledb.DB_TYPE_VARCHAR }, - // P_CITY: { val: body.P_CITY, type: oracledb.DB_TYPE_VARCHAR }, - // P_STATE: { val: body.P_STATE, type: oracledb.DB_TYPE_VARCHAR }, - // P_ZIP: { val: body.P_ZIP, type: oracledb.DB_TYPE_VARCHAR }, - // P_COUNTRY: { val: body.P_COUNTRY, type: oracledb.DB_TYPE_VARCHAR }, - // P_ISSUINGREGION: { val: body.P_ISSUINGREGION, type: oracledb.DB_TYPE_VARCHAR }, - // P_REPLACEMENTREGION: { val: body.P_REPLACEMENTREGION, type: oracledb.DB_TYPE_VARCHAR }, - // P_BONDSURETY: { val: body.P_BONDSURETY, type: oracledb.DB_TYPE_VARCHAR }, - // P_CARGOPOLICYNO: { val: body.P_CARGOPOLICYNO, type: oracledb.DB_TYPE_VARCHAR }, - // P_CARGOSURETY: { val: body.P_CARGOSURETY, type: oracledb.DB_TYPE_VARCHAR }, - // P_USER_ID: { val: body.P_USER_ID, type: oracledb.DB_TYPE_VARCHAR }, - // P_NOTES: { val: body.P_NOTES, type: oracledb.DB_TYPE_VARCHAR }, - // P_FILEIDS: { val: body.P_FILEIDS, type: oracledb.DB_TYPE_VARCHAR }, - // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - // await connection.commit(); - - // const fres = await result.outBinds.P_CURSOR.getRows(); - - // if (fres.length > 0 && fres[0].ERRORMESG) { - // this.logger.warn(fres[0].ERRORMESG); - // throw new BadRequestException(fres[0].ERRORMESG) - // } - - // // return fres[0]; - // return { statusCode: 201, message: "Createdted Successfully", ...fres[0] }; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('insertNewServiceProvider 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 insertNewServiceProvider(body: InsertNewServiceProviderDTO) { const newBody = { @@ -202,177 +121,6 @@ export class SpService { } } - // async updateServiceProviderX(body: UpdateServiceProviderDTO) { - - // const newBody = { - // p_spid: null, - // p_name: null, - // P_LOOKUPCODE: null, - // P_ADDRESS1: null, - // P_ADDRESS2: null, - // P_CITY: null, - // P_STATE: null, - // P_ZIP: null, - // P_COUNTRY: null, - // P_ISSUINGREGION: null, - // P_REPLACEMENTREGION: null, - // P_BONDSURETY: null, - // P_CARGOPOLICYNO: null, - // P_CARGOSURETY: null, - // P_USER_ID: null - // }; - - // const reqBody = JSON.parse(JSON.stringify(body)); - - // function setEmptyStringsToNull(obj) { - // Object.keys(obj).forEach((key) => { - // if (typeof obj[key] === 'object' && obj[key] !== null) { - // setEmptyStringsToNull(obj[key]); - // } else if (obj[key] === '') { - // obj[key] = null; - // } - // }); - // } - - // setEmptyStringsToNull(reqBody); - - // const finalBody: UpdateServiceProviderDTO = { ...newBody, ...reqBody }; - - // let connection; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.UpdateSP( - // :P_SPID, - // :P_NAME, - // :P_LOOKUPCODE, - // :P_ADDRESS1, - // :P_ADDRESS2, - // :P_CITY, - // :P_STATE, - // :P_ZIP, - // :P_COUNTRY, - // :P_BONDSURETY, - // :P_CARGOPOLICYNO, - // :P_CARGOSURETY, - // :P_REPLACEMENTREGION, - // :P_ISSUINGREGION, - // :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, - // }, - // P_LOOKUPCODE: { - // val: finalBody.P_LOOKUPCODE, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDRESS1: { - // val: finalBody.P_ADDRESS1, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ADDRESS2: { - // val: finalBody.P_ADDRESS2, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_CITY: { - // val: finalBody.P_CITY, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_STATE: { - // val: finalBody.P_STATE, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ZIP: { - // val: finalBody.P_ZIP, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_COUNTRY: { - // val: finalBody.P_COUNTRY, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_BONDSURETY: { - // val: finalBody.P_BONDSURETY, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_CARGOPOLICYNO: { - // val: finalBody.P_CARGOPOLICYNO, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_CARGOSURETY: { - // val: finalBody.P_CARGOSURETY, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_REPLACEMENTREGION: { - // val: finalBody.P_REPLACEMENTREGION, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_ISSUINGREGION: { - // val: finalBody.P_ISSUINGREGION, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_USER_ID: { - // val: finalBody.P_USER_ID, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_NOTES: { - // val: finalBody.P_NOTES, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_FILEIDS: { - // val: finalBody.P_FILEIDS, - // type: oracledb.DB_TYPE_VARCHAR, - // }, - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - - // await connection.commit(); - - // const fres = await result.outBinds.P_CURSOR.getRows(); - - // if (fres.length > 0 && fres[0].ERRORMESG) { - // this.logger.warn(fres[0].ERRORMESG); - // throw new BadRequestException(fres[0].ERRORMESG) - // } - - // return { statusCode: 200, message: "Updated Successfully" }; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('updateServiceProvider 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 updateServiceProvider(body: UpdateServiceProviderDTO) { const newBody = { @@ -480,66 +228,6 @@ export class SpService { } } - // async getAllServiceprovidersX() { - // let connection; - // let rows: any = []; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.GetAllSPs(:P_CURSOR); - // END;`, - // { - // P_CURSOR: { - // type: oracledb.CURSOR, - // dir: oracledb.BIND_OUT, - // }, - // }, - // { - // outFormat: oracledb.OUT_FORMAT_OBJECT, - // }, - // ); - - // if (result.outBinds && result.outBinds.P_CURSOR) { - // const cursor = result.outBinds.P_CURSOR; - // let rowsBatch; - - // do { - // rowsBatch = await cursor.getRows(100); - // rows = rows.concat(rowsBatch); - // } while (rowsBatch.length > 0); - - // await cursor.close(); - - // if (rows.length > 0 && rows[0].ERRORMESG) { - // throw new BadRequestException(rows[0].ERRORMESG); - // } - - // return rows; - // } else { - // throw new BadRequestException(); - // } - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // this.logger.error('getAllServiceproviders 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 getAllServiceproviders() { @@ -572,74 +260,6 @@ export class SpService { } } - // async getServiceproviderByIDX(body: SPID_DTO) { - // let connection; - // let rows: any = []; - // try { - // connection = await this.oracleDBService.getConnection(); - // if (!connection) { - // throw new InternalServerException(); - // } - - // const result = await connection.execute( - // `BEGIN - // USCIB_Managed_Pkg.GetSPbySPID(:P_SPID,:P_CURSOR); - // END;`, - // { - // P_SPID: { - // val: body.P_SPID, - // 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); - // rows = rows.concat(rowsBatch); - // } while (rowsBatch.length > 0); - - // await cursor.close(); - // } else { - // throw new BadRequestException(); - // } - - // if (rows.length > 0 && rows[0].ERRORMESG) { - // throw new BadRequestException(rows[0].ERRORMESG); - // } - - // return rows; - // } catch (error) { - // if (error instanceof BadRequestException) { - // this.logger.warn(error.message); - // throw error; - // } - // else if (error.message === "NJS-107: invalid cursor") { - // this.logger.warn(error.message); - // throw new BadRequestException(); - // } - // this.logger.error('getServiceproviderByID failed', error.stack || error); - // throw new InternalServerException(); - // } finally { - // if (connection) { - // try { - // await connection.close(); - // } catch (closeErr) { - // this.logger.error('Failed to close DB connection', closeErr); - // } - // } - // } - // } async getServiceproviderByID(body: SPID_DTO) { diff --git a/src/oracle/user-maintenance/user-maintenance.service.ts b/src/oracle/user-maintenance/user-maintenance.service.ts index 553ca74..f473c93 100644 --- a/src/oracle/user-maintenance/user-maintenance.service.ts +++ b/src/oracle/user-maintenance/user-maintenance.service.ts @@ -30,19 +30,6 @@ export class UserMaintenanceService { constructor(private readonly oracleDBService: OracleDBService) { } - // private async fetchCursor(cursor: oracledb.ResultSet): Promise { - // try { - // const rows = await cursor.getRows(); // or getRows(1000) if needed - // await cursor.close(); - // return rows; - // } catch (err) { - // this.logger.error('Failed to fetch from cursor', err.stack || err); - // throw new InternalServerException("Error reading data from database."); - // } - // } - - // SP_USER_DETAILS - async GetSPUserDetails(body: USERID_DTO): Promise { let connection; diff --git a/src/utils/helper.ts b/src/utils/helper.ts index e7e0e89..ce1d39a 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -46,4 +46,14 @@ export const fetchCursor = async (cursor: oracledb.ResultSet, context: str logger.error(`[${context}] Failed to fetch from cursor`, err.stack || err); throw new InternalServerErrorException('Error reading data from database.'); } -}; +}; + +export const setEmptyStringsToNull = (obj: any): void => { + Object.keys(obj).forEach((key) => { + if (typeof obj[key] === 'object' && obj[key] !== null) { + setEmptyStringsToNull(obj[key]); + } else if (obj[key] === '') { + obj[key] = null; + } + }); +}