modified client api
This commit is contained in:
parent
7d97c9b0b6
commit
aff1e69dec
@ -1,28 +1,87 @@
|
|||||||
import { MssqlConfig, OracleConfig } from 'ormconfig';
|
import { MssqlConfig, OracleConfig } from 'ormconfig';
|
||||||
import { createPool, Pool, Connection as cob } from 'oracledb';
|
import { createPool, Pool, Connection as cob } from 'oracledb';
|
||||||
import { Connection, ConnectionPool } from 'mssql';
|
import { Connection, ConnectionPool } from 'mssql';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
|
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
|
||||||
|
|
||||||
|
// @Injectable()
|
||||||
|
// export class OracleDBService {
|
||||||
|
// private pool: Pool;
|
||||||
|
|
||||||
|
// constructor() {
|
||||||
|
// this.initializePool();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// private async initializePool() {
|
||||||
|
// this.pool = await createPool({
|
||||||
|
// ...OracleConfig,
|
||||||
|
// poolMin: 1,
|
||||||
|
// poolMax: 10,
|
||||||
|
// poolIncrement: 1,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
|
// async getConnection(): Promise<cob> {
|
||||||
|
// const connection = await this.pool.getConnection();
|
||||||
|
// return connection;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OracleDBService {
|
export class OracleDBService {
|
||||||
private pool: Pool;
|
private pool: Pool | null = null;
|
||||||
|
|
||||||
|
private readonly logger = new Logger(OracleDBService.name);
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.initializePool();
|
this.initializePool().catch(err => {
|
||||||
|
Logger.error('Error initializing Oracle DB pool', err);
|
||||||
|
// You might want to rethrow or handle accordingly depending on app behavior
|
||||||
|
throw new InternalServerException();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initializePool() {
|
private async initializePool(): Promise<void> {
|
||||||
|
try {
|
||||||
this.pool = await createPool({
|
this.pool = await createPool({
|
||||||
...OracleConfig,
|
...OracleConfig,
|
||||||
poolMin: 1,
|
poolMin: 1,
|
||||||
poolMax: 10,
|
poolMax: 10,
|
||||||
poolIncrement: 1,
|
poolIncrement: 1,
|
||||||
});
|
});
|
||||||
|
Logger.log('Oracle connection pool created successfully');
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error('Failed to create Oracle DB pool:', error);
|
||||||
|
throw error; // Optional: rethrow to allow external handling
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getConnection(): Promise<cob> {
|
async getConnection(): Promise<cob> {
|
||||||
|
if (!this.pool) {
|
||||||
|
Logger.error('Attempted to get a connection before pool was initialized');
|
||||||
|
throw new InternalServerException('Database connection pool not initialized');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const connection = await this.pool.getConnection();
|
const connection = await this.pool.getConnection();
|
||||||
return connection;
|
return connection;
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error('Failed to get Oracle DB connection:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optionally add a close method to gracefully shut down the pool
|
||||||
|
async closePool(): Promise<void> {
|
||||||
|
if (this.pool) {
|
||||||
|
try {
|
||||||
|
await this.pool.close(10); // 10-second timeout
|
||||||
|
Logger.log('Oracle DB pool closed successfully');
|
||||||
|
} catch (error) {
|
||||||
|
Logger.error('Error closing Oracle DB pool:', error);
|
||||||
|
throw new InternalServerException()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||||
import { ManageClientsService } from './manage-clients.service';
|
import { ManageClientsService } from './manage-clients.service';
|
||||||
import { ApiTags } from '@nestjs/swagger';
|
import { ApiTags } from '@nestjs/swagger';
|
||||||
import { CreateAdditionalClientContactsDTO, CreateAdditionalClientLocationsDTO, CreateClientDataDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from 'src/oracle/manage-clients/manage-clients.dto';
|
import { CreateClientContactsDTO, CreateClientDataDTO, CreateClientLocationsDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from 'src/oracle/manage-clients/manage-clients.dto';
|
||||||
|
|
||||||
@Controller('mssql')
|
@Controller('mssql')
|
||||||
export class ManageClientsController {
|
export class ManageClientsController {
|
||||||
@ -33,13 +33,13 @@ export class ManageClientsController {
|
|||||||
|
|
||||||
@ApiTags('Manage Clients - Mssql')
|
@ApiTags('Manage Clients - Mssql')
|
||||||
@Post('CreateAdditionalClientContacts')
|
@Post('CreateAdditionalClientContacts')
|
||||||
CreateClientContact(@Body() body: CreateAdditionalClientContactsDTO) {
|
CreateClientContact(@Body() body: CreateClientContactsDTO) {
|
||||||
return this.manageClientsService.CreateClientContact(body);
|
return this.manageClientsService.CreateClientContact(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags('Manage Clients - Mssql')
|
@ApiTags('Manage Clients - Mssql')
|
||||||
@Post('CreateAdditionalClientLocations')
|
@Post('CreateAdditionalClientLocations')
|
||||||
CreateClientLocation(@Body() body: CreateAdditionalClientLocationsDTO) {
|
CreateClientLocation(@Body() body: CreateClientLocationsDTO) {
|
||||||
return this.manageClientsService.CreateClientLocation(body);
|
return this.manageClientsService.CreateClientLocation(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Connection, Request } from 'mssql';
|
import { Connection, Request } from 'mssql';
|
||||||
import { MssqlDBService } from 'src/db/db.service';
|
import { MssqlDBService } from 'src/db/db.service';
|
||||||
import { CreateAdditionalClientContactsDTO, CreateAdditionalClientLocationsDTO, CreateClientDataDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from 'src/oracle/manage-clients/manage-clients.dto';
|
import { CreateClientContactsDTO, CreateClientDataDTO, CreateClientLocationsDTO, GetPreparerByClientidContactsByClientidLocByClientidDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from 'src/oracle/manage-clients/manage-clients.dto';
|
||||||
import * as mssql from 'mssql';
|
import * as mssql from 'mssql';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -70,18 +70,18 @@ export class ManageClientsService {
|
|||||||
contactTable.columns.add('MobileNo', mssql.VarChar(20));
|
contactTable.columns.add('MobileNo', mssql.VarChar(20));
|
||||||
contactTable.columns.add('FaxNo', mssql.VarChar(20));
|
contactTable.columns.add('FaxNo', mssql.VarChar(20));
|
||||||
|
|
||||||
finalBody.p_contactstable.forEach((contact) => {
|
// finalBody.p_contactstable.forEach((contact) => {
|
||||||
contactTable.rows.add(
|
// contactTable.rows.add(
|
||||||
contact.FirstName,
|
// contact.FirstName,
|
||||||
contact.LastName,
|
// contact.LastName,
|
||||||
contact.MiddleInitial,
|
// contact.MiddleInitial,
|
||||||
contact.Title,
|
// contact.Title,
|
||||||
contact.EmailAddress,
|
// contact.EmailAddress,
|
||||||
contact.PhoneNo,
|
// contact.PhoneNo,
|
||||||
contact.MobileNo,
|
// contact.MobileNo,
|
||||||
contact.FaxNo,
|
// contact.FaxNo,
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
request.input('p_contactstable', contactTable);
|
request.input('p_contactstable', contactTable);
|
||||||
|
|
||||||
@ -95,17 +95,17 @@ export class ManageClientsService {
|
|||||||
clientLocAddressTable.columns.add('Zip', mssql.VarChar(10));
|
clientLocAddressTable.columns.add('Zip', mssql.VarChar(10));
|
||||||
clientLocAddressTable.columns.add('Country', mssql.VarChar(2));
|
clientLocAddressTable.columns.add('Country', mssql.VarChar(2));
|
||||||
|
|
||||||
finalBody.p_clientlocaddresstable.forEach((contact) => {
|
// finalBody.p_clientlocaddresstable.forEach((contact) => {
|
||||||
clientLocAddressTable.rows.add(
|
// clientLocAddressTable.rows.add(
|
||||||
contact.Nameof,
|
// contact.Nameof,
|
||||||
contact.Address1,
|
// contact.Address1,
|
||||||
contact.Address2,
|
// contact.Address2,
|
||||||
contact.City,
|
// contact.City,
|
||||||
contact.State,
|
// contact.State,
|
||||||
contact.Zip,
|
// contact.Zip,
|
||||||
contact.Country,
|
// contact.Country,
|
||||||
);
|
// );
|
||||||
});
|
// });
|
||||||
|
|
||||||
request.input('p_clientlocaddresstable', clientLocAddressTable);
|
request.input('p_clientlocaddresstable', clientLocAddressTable);
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ export class ManageClientsService {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CreateClientContact = async (body: CreateAdditionalClientContactsDTO) => {
|
CreateClientContact = async (body: CreateClientContactsDTO) => {
|
||||||
const newBody = {
|
const newBody = {
|
||||||
p_spid: null,
|
p_spid: null,
|
||||||
p_clientid: null,
|
p_clientid: null,
|
||||||
@ -211,7 +211,7 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
setEmptyStringsToNull(reqBody);
|
setEmptyStringsToNull(reqBody);
|
||||||
|
|
||||||
const finalBody: CreateAdditionalClientContactsDTO = {
|
const finalBody: CreateClientContactsDTO = {
|
||||||
...newBody,
|
...newBody,
|
||||||
...reqBody,
|
...reqBody,
|
||||||
};
|
};
|
||||||
@ -371,7 +371,7 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CreateClientLocation = async (body: CreateAdditionalClientLocationsDTO) => {
|
CreateClientLocation = async (body: CreateClientLocationsDTO) => {
|
||||||
const newBody = {
|
const newBody = {
|
||||||
p_spid: null,
|
p_spid: null,
|
||||||
p_clientid: null,
|
p_clientid: null,
|
||||||
@ -394,7 +394,7 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
setEmptyStringsToNull(reqBody);
|
setEmptyStringsToNull(reqBody);
|
||||||
|
|
||||||
const finalBody: CreateAdditionalClientLocationsDTO = {
|
const finalBody: CreateClientLocationsDTO = {
|
||||||
...newBody,
|
...newBody,
|
||||||
...reqBody,
|
...reqBody,
|
||||||
};
|
};
|
||||||
@ -431,7 +431,6 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
request.input('p_clientlocaddresstable', clientLocAddressTable);
|
request.input('p_clientlocaddresstable', clientLocAddressTable);
|
||||||
|
|
||||||
request.input('p_defcontactflag', mssql.VarChar(1), finalBody.p_defcontactflag);
|
|
||||||
request.input('p_userid', mssql.VarChar(100), finalBody.p_userid);
|
request.input('p_userid', mssql.VarChar(100), finalBody.p_userid);
|
||||||
|
|
||||||
const result = await request.execute('carnetsys.CreateClientLocation');
|
const result = await request.execute('carnetsys.CreateClientLocation');
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||||
import { ManageClientsService } from './manage-clients.service';
|
import { ManageClientsService } from './manage-clients.service';
|
||||||
import {
|
import {
|
||||||
CreateAdditionalClientContactsDTO,
|
CreateClientContactsDTO,
|
||||||
CreateAdditionalClientLocationsDTO,
|
|
||||||
CreateClientDataDTO,
|
CreateClientDataDTO,
|
||||||
|
CreateClientLocationsDTO,
|
||||||
GetPreparerByClientidContactsByClientidLocByClientidDTO,
|
GetPreparerByClientidContactsByClientidLocByClientidDTO,
|
||||||
GetPreparersDTO,
|
GetPreparersDTO,
|
||||||
UpdateClientContactsDTO,
|
UpdateClientContactsDTO,
|
||||||
@ -41,14 +41,14 @@ export class ManageClientsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags('Manage Clients - Oracle')
|
@ApiTags('Manage Clients - Oracle')
|
||||||
@Post('CreateAdditionalClientContacts')
|
@Post('CreateClientContacts')
|
||||||
CreateClientContact(@Body() body: CreateAdditionalClientContactsDTO) {
|
CreateClientContact(@Body() body: CreateClientContactsDTO) {
|
||||||
return this.manageClientsService.CreateClientContact(body);
|
return this.manageClientsService.CreateClientContact(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags('Manage Clients - Oracle')
|
@ApiTags('Manage Clients - Oracle')
|
||||||
@Post('CreateAdditionalClientLocations')
|
@Post('CreateClientLocations')
|
||||||
CreateClientLocation(@Body() body: CreateAdditionalClientLocationsDTO) {
|
CreateClientLocation(@Body() body: CreateClientLocationsDTO) {
|
||||||
return this.manageClientsService.CreateClientLocation(body);
|
return this.manageClientsService.CreateClientLocation(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -171,21 +171,21 @@ export class CreateClientDataDTO {
|
|||||||
@IsDefined({ message: 'Property p_userid is required' })
|
@IsDefined({ message: 'Property p_userid is required' })
|
||||||
p_userid: string;
|
p_userid: string;
|
||||||
|
|
||||||
@ApiProperty({ required: true, type: () => [p_contactstableDTO] })
|
// @ApiProperty({ required: true, type: () => [p_contactstableDTO] })
|
||||||
@Type(() => p_contactstableDTO)
|
// @Type(() => p_contactstableDTO)
|
||||||
@ValidateNested({ each: true })
|
// @ValidateNested({ each: true })
|
||||||
@IsArray({ message: 'Property p_contactstable allows only array type' })
|
// @IsArray({ message: 'Property p_contactstable allows only array type' })
|
||||||
@IsDefined({ message: 'Property p_contactstable is required' })
|
// @IsDefined({ message: 'Property p_contactstable is required' })
|
||||||
p_contactstable: p_contactstableDTO[];
|
// p_contactstable: p_contactstableDTO[];
|
||||||
|
|
||||||
@ApiProperty({ required: true, type: () => [p_clientlocaddresstableDTO] })
|
// @ApiProperty({ required: true, type: () => [p_clientlocaddresstableDTO] })
|
||||||
@Type(() => p_clientlocaddresstableDTO)
|
// @Type(() => p_clientlocaddresstableDTO)
|
||||||
@ValidateNested({ each: true })
|
// @ValidateNested({ each: true })
|
||||||
@IsArray({
|
// @IsArray({
|
||||||
message: 'Property p_clientlocaddresstable allows only array type',
|
// message: 'Property p_clientlocaddresstable allows only array type',
|
||||||
})
|
// })
|
||||||
@IsDefined({ message: 'Property p_clientlocaddresstable is required' })
|
// @IsDefined({ message: 'Property p_clientlocaddresstable is required' })
|
||||||
p_clientlocaddresstable: p_clientlocaddresstableDTO[];
|
// p_clientlocaddresstable: p_clientlocaddresstableDTO[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateClientDTO {
|
export class UpdateClientDTO {
|
||||||
@ -508,7 +508,7 @@ export class UpdateClientLocationsDTO {
|
|||||||
p_userid: string;
|
p_userid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateAdditionalClientContactsDTO {
|
export class CreateClientContactsDTO {
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@Max(999999999, { message: 'Property p_spid must not exceed 999999999' })
|
@Max(999999999, { message: 'Property p_spid must not exceed 999999999' })
|
||||||
@Min(0, { message: 'Property p_spid must be at least 0 or more' })
|
@Min(0, { message: 'Property p_spid must be at least 0 or more' })
|
||||||
@ -549,7 +549,7 @@ export class CreateAdditionalClientContactsDTO {
|
|||||||
p_userid: string;
|
p_userid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateAdditionalClientLocationsDTO {
|
export class CreateClientLocationsDTO {
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@Max(999999999, { message: 'Property p_spid must not exceed 999999999' })
|
@Max(999999999, { message: 'Property p_spid must not exceed 999999999' })
|
||||||
@Min(0, { message: 'Property p_spid must be at least 0 or more' })
|
@Min(0, { message: 'Property p_spid must be at least 0 or more' })
|
||||||
@ -575,13 +575,13 @@ export class CreateAdditionalClientLocationsDTO {
|
|||||||
@IsDefined({ message: 'Property p_clientlocaddresstable is required' })
|
@IsDefined({ message: 'Property p_clientlocaddresstable is required' })
|
||||||
p_clientlocaddresstable: p_clientlocaddresstableDTO[];
|
p_clientlocaddresstable: p_clientlocaddresstableDTO[];
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
// @ApiProperty({ required: true })
|
||||||
@Length(0, 1, {
|
// @Length(0, 1, {
|
||||||
message: 'Property p_defcontactflag must be exactly 1 character',
|
// message: 'Property p_defcontactflag must be exactly 1 character',
|
||||||
})
|
// })
|
||||||
@IsString({ message: 'Property p_defcontactflag must be a string' })
|
// @IsString({ message: 'Property p_defcontactflag must be a string' })
|
||||||
@IsDefined({ message: 'Property p_defcontactflag is required' })
|
// @IsDefined({ message: 'Property p_defcontactflag is required' })
|
||||||
p_defcontactflag: string;
|
// p_defcontactflag: string;
|
||||||
|
|
||||||
@ApiProperty({ required: true })
|
@ApiProperty({ required: true })
|
||||||
@Length(0, 100, {
|
@Length(0, 100, {
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { OracleDBService } from 'src/db/db.service';
|
import { OracleDBService } from 'src/db/db.service';
|
||||||
import {
|
import {
|
||||||
CreateAdditionalClientContactsDTO,
|
CreateClientContactsDTO,
|
||||||
CreateAdditionalClientLocationsDTO,
|
|
||||||
CreateClientDataDTO,
|
CreateClientDataDTO,
|
||||||
|
CreateClientLocationsDTO,
|
||||||
GetPreparerByClientidContactsByClientidLocByClientidDTO,
|
GetPreparerByClientidContactsByClientidLocByClientidDTO,
|
||||||
GetPreparersDTO,
|
GetPreparersDTO,
|
||||||
p_clientlocaddresstableDTO,
|
p_clientlocaddresstableDTO,
|
||||||
@ -13,10 +13,14 @@ import {
|
|||||||
} from './manage-clients.dto';
|
} from './manage-clients.dto';
|
||||||
import { p_contactstableDTO } from '../manage-holders/manage-holders.dto';
|
import { p_contactstableDTO } from '../manage-holders/manage-holders.dto';
|
||||||
import * as oracledb from 'oracledb';
|
import * as oracledb from 'oracledb';
|
||||||
|
import { BadRequestException } from 'src/exceptions/badRequest.exception';
|
||||||
|
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ManageClientsService {
|
export class ManageClientsService {
|
||||||
constructor(private readonly oracleDBService: OracleDBService) {}
|
private readonly logger = new Logger(ManageClientsService.name);
|
||||||
|
|
||||||
|
constructor(private readonly oracleDBService: OracleDBService) { }
|
||||||
|
|
||||||
CreateClientData = async (body: CreateClientDataDTO) => {
|
CreateClientData = async (body: CreateClientDataDTO) => {
|
||||||
const newBody = {
|
const newBody = {
|
||||||
@ -32,8 +36,6 @@ export class ManageClientsService {
|
|||||||
p_issuingregion: null,
|
p_issuingregion: null,
|
||||||
p_revenuelocation: null,
|
p_revenuelocation: null,
|
||||||
p_userid: null,
|
p_userid: null,
|
||||||
p_contactstable: null,
|
|
||||||
p_clientlocaddresstable: null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const reqBody = JSON.parse(JSON.stringify(body));
|
const reqBody = JSON.parse(JSON.stringify(body));
|
||||||
@ -53,9 +55,9 @@ export class ManageClientsService {
|
|||||||
const finalBody: CreateClientDataDTO = { ...newBody, ...reqBody };
|
const finalBody: CreateClientDataDTO = { ...newBody, ...reqBody };
|
||||||
|
|
||||||
let connection;
|
let connection;
|
||||||
let p_clientcursor_rows = [];
|
let p_clientcursor_rows: any = [];
|
||||||
let p_clientcontactcursor_rows = [];
|
// let p_clientcontactcursor_rows = [];
|
||||||
let p_clientloccursor_rows = [];
|
// let p_clientloccursor_rows = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
@ -68,118 +70,118 @@ export class ManageClientsService {
|
|||||||
// return { res:res.rows };
|
// return { res:res.rows };
|
||||||
|
|
||||||
// const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY');
|
// const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY');
|
||||||
const CONTACTSTABLE = await connection.getDbObjectClass(
|
// const CONTACTSTABLE = await connection.getDbObjectClass(
|
||||||
'CARNETSYS.CONTACTSTABLE',
|
// 'CARNETSYS.CONTACTSTABLE',
|
||||||
);
|
// );
|
||||||
// const CLIENTLOCADDRESSARRAY = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSARRAY');
|
// const CLIENTLOCADDRESSARRAY = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSARRAY');
|
||||||
const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass(
|
// const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass(
|
||||||
'CARNETSYS.CLIENTLOCADDRESSTABLE',
|
// 'CARNETSYS.CLIENTLOCADDRESSTABLE',
|
||||||
);
|
// );
|
||||||
|
|
||||||
// Check if CONTACTSTABLE is a constructor
|
// Check if CONTACTSTABLE is a constructor
|
||||||
if (typeof CONTACTSTABLE !== 'function') {
|
// if (typeof CONTACTSTABLE !== 'function') {
|
||||||
throw new Error('CONTACTSTABLE is not a constructor');
|
// throw new Error('CONTACTSTABLE is not a constructor');
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Check if CLIENTLOCADDRESSTABLE is a constructor
|
// // Check if CLIENTLOCADDRESSTABLE is a constructor
|
||||||
if (typeof CLIENTLOCADDRESSTABLE !== 'function') {
|
// if (typeof CLIENTLOCADDRESSTABLE !== 'function') {
|
||||||
throw new Error('CLIENTLOCADDRESSTABLE is not a constructor');
|
// throw new Error('CLIENTLOCADDRESSTABLE is not a constructor');
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function CREATECONTACTSTABLE_INSTANCE(
|
// async function CREATECONTACTSTABLE_INSTANCE(
|
||||||
connection,
|
// connection,
|
||||||
FirstName,
|
// FirstName,
|
||||||
LastName,
|
// LastName,
|
||||||
MiddleInitial,
|
// MiddleInitial,
|
||||||
Title,
|
// Title,
|
||||||
EmailAddress,
|
// EmailAddress,
|
||||||
PhoneNo,
|
// PhoneNo,
|
||||||
MobileNo,
|
// MobileNo,
|
||||||
FaxNo,
|
// FaxNo,
|
||||||
) {
|
// ) {
|
||||||
const result = await connection.execute(
|
// const result = await connection.execute(
|
||||||
`SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`,
|
// `SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`,
|
||||||
{
|
// {
|
||||||
FirstName,
|
// FirstName,
|
||||||
LastName,
|
// LastName,
|
||||||
MiddleInitial,
|
// MiddleInitial,
|
||||||
Title,
|
// Title,
|
||||||
EmailAddress,
|
// EmailAddress,
|
||||||
PhoneNo,
|
// PhoneNo,
|
||||||
MobileNo,
|
// MobileNo,
|
||||||
FaxNo,
|
// FaxNo,
|
||||||
},
|
// },
|
||||||
);
|
// );
|
||||||
return result.rows[0][0];
|
// return result.rows[0][0];
|
||||||
}
|
// }
|
||||||
|
|
||||||
async function CREATECLIENTLOCADDRESSTABLE_INSTANCE(
|
// async function CREATECLIENTLOCADDRESSTABLE_INSTANCE(
|
||||||
connection,
|
// connection,
|
||||||
Nameof,
|
// Nameof,
|
||||||
Address1,
|
// Address1,
|
||||||
Address2,
|
// Address2,
|
||||||
City,
|
// City,
|
||||||
State,
|
// State,
|
||||||
Zip,
|
// Zip,
|
||||||
Country,
|
// Country,
|
||||||
) {
|
// ) {
|
||||||
const result = await connection.execute(
|
// const result = await connection.execute(
|
||||||
`SELECT CARNETSYS.CLIENTLOCADDRESSARRAY(:Nameof, :Address1, :Address2, :City, :State, :Zip, :Country) FROM dual`,
|
// `SELECT CARNETSYS.CLIENTLOCADDRESSARRAY(:Nameof, :Address1, :Address2, :City, :State, :Zip, :Country) FROM dual`,
|
||||||
{
|
// {
|
||||||
Nameof,
|
// Nameof,
|
||||||
Address1,
|
// Address1,
|
||||||
Address2,
|
// Address2,
|
||||||
City,
|
// City,
|
||||||
State,
|
// State,
|
||||||
Zip,
|
// Zip,
|
||||||
Country,
|
// Country,
|
||||||
},
|
// },
|
||||||
);
|
// );
|
||||||
return result.rows[0][0];
|
// return result.rows[0][0];
|
||||||
}
|
// }
|
||||||
|
|
||||||
const CONTACTSARRAY = finalBody.p_contactstable
|
// const CONTACTSARRAY = finalBody.p_contactstable
|
||||||
? await Promise.all(
|
// ? await Promise.all(
|
||||||
finalBody.p_contactstable.map(async (x: p_contactstableDTO) => {
|
// finalBody.p_contactstable.map(async (x: p_contactstableDTO) => {
|
||||||
return await CREATECONTACTSTABLE_INSTANCE(
|
// return await CREATECONTACTSTABLE_INSTANCE(
|
||||||
connection,
|
// connection,
|
||||||
x.FirstName,
|
// x.FirstName,
|
||||||
x.LastName,
|
// x.LastName,
|
||||||
x.MiddleInitial,
|
// x.MiddleInitial,
|
||||||
x.Title,
|
// x.Title,
|
||||||
x.EmailAddress,
|
// x.EmailAddress,
|
||||||
x.PhoneNo,
|
// x.PhoneNo,
|
||||||
x.MobileNo,
|
// x.MobileNo,
|
||||||
x.FaxNo,
|
// x.FaxNo,
|
||||||
);
|
// );
|
||||||
}),
|
// }),
|
||||||
)
|
// )
|
||||||
: [];
|
// : [];
|
||||||
|
|
||||||
const CLIENTLOCADDRESSARRAY = finalBody.p_clientlocaddresstable
|
// const CLIENTLOCADDRESSARRAY = finalBody.p_clientlocaddresstable
|
||||||
? await Promise.all(
|
// ? await Promise.all(
|
||||||
finalBody.p_clientlocaddresstable.map(
|
// finalBody.p_clientlocaddresstable.map(
|
||||||
async (x: p_clientlocaddresstableDTO) => {
|
// async (x: p_clientlocaddresstableDTO) => {
|
||||||
return await CREATECLIENTLOCADDRESSTABLE_INSTANCE(
|
// return await CREATECLIENTLOCADDRESSTABLE_INSTANCE(
|
||||||
connection,
|
// connection,
|
||||||
x.Nameof,
|
// x.Nameof,
|
||||||
x.Address1,
|
// x.Address1,
|
||||||
x.Address2,
|
// x.Address2,
|
||||||
x.City,
|
// x.City,
|
||||||
x.State,
|
// x.State,
|
||||||
x.Zip,
|
// x.Zip,
|
||||||
x.Country,
|
// x.Country,
|
||||||
);
|
// );
|
||||||
},
|
// },
|
||||||
),
|
// ),
|
||||||
)
|
// )
|
||||||
: [];
|
// : [];
|
||||||
|
|
||||||
// Create an instance of GLTABLE
|
// Create an instance of GLTABLE
|
||||||
const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY);
|
// const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY);
|
||||||
const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE(
|
// const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE(
|
||||||
CLIENTLOCADDRESSARRAY,
|
// CLIENTLOCADDRESSARRAY,
|
||||||
);
|
// );
|
||||||
|
|
||||||
// return {CONTACTSTABLE_INSTANCE, CLIENTLOCADDRESSTABLE_INSTANCE}
|
// return {CONTACTSTABLE_INSTANCE, CLIENTLOCADDRESSTABLE_INSTANCE}
|
||||||
|
|
||||||
@ -198,11 +200,7 @@ export class ManageClientsService {
|
|||||||
:p_issuingregion,
|
:p_issuingregion,
|
||||||
:p_revenuelocation,
|
:p_revenuelocation,
|
||||||
:p_userid,
|
:p_userid,
|
||||||
:p_contactstable,
|
:p_clientcursor
|
||||||
:p_clientlocaddresstable,
|
|
||||||
:p_clientcursor,
|
|
||||||
:p_clientcontactcursor,
|
|
||||||
:p_clientloccursor
|
|
||||||
);
|
);
|
||||||
END;`,
|
END;`,
|
||||||
{
|
{
|
||||||
@ -256,26 +254,26 @@ export class ManageClientsService {
|
|||||||
val: finalBody.p_userid ? finalBody.p_userid : null,
|
val: finalBody.p_userid ? finalBody.p_userid : null,
|
||||||
type: oracledb.DB_TYPE_NVARCHAR,
|
type: oracledb.DB_TYPE_NVARCHAR,
|
||||||
},
|
},
|
||||||
p_contactstable: {
|
// p_contactstable: {
|
||||||
val: CONTACTSTABLE_INSTANCE,
|
// val: CONTACTSTABLE_INSTANCE,
|
||||||
type: oracledb.DB_TYPE_OBJECT,
|
// type: oracledb.DB_TYPE_OBJECT,
|
||||||
},
|
// },
|
||||||
p_clientlocaddresstable: {
|
// p_clientlocaddresstable: {
|
||||||
val: CLIENTLOCADDRESSTABLE_INSTANCE,
|
// val: CLIENTLOCADDRESSTABLE_INSTANCE,
|
||||||
type: oracledb.DB_TYPE_OBJECT,
|
// type: oracledb.DB_TYPE_OBJECT,
|
||||||
},
|
// },
|
||||||
p_clientcursor: {
|
p_clientcursor: {
|
||||||
type: oracledb.CURSOR,
|
type: oracledb.CURSOR,
|
||||||
dir: oracledb.BIND_OUT,
|
dir: oracledb.BIND_OUT,
|
||||||
},
|
},
|
||||||
p_clientcontactcursor: {
|
// p_clientcontactcursor: {
|
||||||
type: oracledb.CURSOR,
|
// type: oracledb.CURSOR,
|
||||||
dir: oracledb.BIND_OUT,
|
// dir: oracledb.BIND_OUT,
|
||||||
},
|
// },
|
||||||
p_clientloccursor: {
|
// p_clientloccursor: {
|
||||||
type: oracledb.CURSOR,
|
// type: oracledb.CURSOR,
|
||||||
dir: oracledb.BIND_OUT,
|
// dir: oracledb.BIND_OUT,
|
||||||
},
|
// },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
||||||
@ -298,53 +296,54 @@ export class ManageClientsService {
|
|||||||
throw new Error('No cursor returned from the stored procedure');
|
throw new Error('No cursor returned from the stored procedure');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.outBinds && result.outBinds.p_clientcontactcursor) {
|
// if (result.outBinds && result.outBinds.p_clientcontactcursor) {
|
||||||
const cursor = result.outBinds.p_clientcontactcursor;
|
// const cursor = result.outBinds.p_clientcontactcursor;
|
||||||
let rowsBatch;
|
// let rowsBatch;
|
||||||
|
|
||||||
do {
|
// do {
|
||||||
rowsBatch = await cursor.getRows(100);
|
// rowsBatch = await cursor.getRows(100);
|
||||||
p_clientcontactcursor_rows =
|
// p_clientcontactcursor_rows =
|
||||||
p_clientcontactcursor_rows.concat(rowsBatch);
|
// p_clientcontactcursor_rows.concat(rowsBatch);
|
||||||
} while (rowsBatch.length > 0);
|
// } while (rowsBatch.length > 0);
|
||||||
|
|
||||||
await cursor.close();
|
// await cursor.close();
|
||||||
} else {
|
// } else {
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
// throw new Error('No cursor returned from the stored procedure');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (result.outBinds && result.outBinds.p_clientloccursor) {
|
||||||
|
// const cursor = result.outBinds.p_clientloccursor;
|
||||||
|
// let rowsBatch;
|
||||||
|
|
||||||
|
// do {
|
||||||
|
// rowsBatch = await cursor.getRows(100);
|
||||||
|
// p_clientloccursor_rows = p_clientloccursor_rows.concat(rowsBatch);
|
||||||
|
// } while (rowsBatch.length > 0);
|
||||||
|
|
||||||
|
// await cursor.close();
|
||||||
|
// } else {
|
||||||
|
// throw new Error('No cursor returned from the stored procedure');
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (p_clientcursor_rows[0].ERRORMESG) {
|
||||||
|
throw new BadRequestException(p_clientcursor_rows[0].ERRORMESG);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.outBinds && result.outBinds.p_clientloccursor) {
|
return { statusCode: 201, message: "Created Successfully" };
|
||||||
const cursor = result.outBinds.p_clientloccursor;
|
|
||||||
let rowsBatch;
|
|
||||||
|
|
||||||
do {
|
} catch (error) {
|
||||||
rowsBatch = await cursor.getRows(100);
|
if (error instanceof BadRequestException) {
|
||||||
p_clientloccursor_rows = p_clientloccursor_rows.concat(rowsBatch);
|
this.logger.warn(error.message);
|
||||||
} while (rowsBatch.length > 0);
|
throw error;
|
||||||
|
|
||||||
await cursor.close();
|
|
||||||
} else {
|
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
|
||||||
}
|
}
|
||||||
|
this.logger.error('CREATECLIENTDATA failed', error.stack || error);
|
||||||
return {
|
throw new InternalServerException();
|
||||||
p_clientcursor: p_clientcursor_rows,
|
} finally {
|
||||||
p_clientcontactcursor: p_clientcontactcursor_rows,
|
|
||||||
p_clientloccursor: p_clientloccursor_rows,
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
if (err instanceof Error) {
|
|
||||||
return { error: err.message };
|
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,7 +381,7 @@ export class ManageClientsService {
|
|||||||
const finalBody: UpdateClientDTO = { ...newBody, ...reqBody };
|
const finalBody: UpdateClientDTO = { ...newBody, ...reqBody };
|
||||||
|
|
||||||
let connection;
|
let connection;
|
||||||
let p_cursor_rows = [];
|
let p_cursor_rows: any = [];
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
@ -478,20 +477,25 @@ export class ManageClientsService {
|
|||||||
throw new Error('No cursor returned from the stored procedure');
|
throw new Error('No cursor returned from the stored procedure');
|
||||||
}
|
}
|
||||||
|
|
||||||
return { p_cursor: p_cursor_rows };
|
if (p_cursor_rows[0].ERRORMESG) {
|
||||||
} catch (err) {
|
throw new BadRequestException(p_cursor_rows[0].ERRORMESG);
|
||||||
if (err instanceof Error) {
|
|
||||||
return { error: err.message };
|
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { statusCode: 200, message: "Updated Successfully" };
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof BadRequestException) {
|
||||||
|
this.logger.warn(error.message);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
finally {
|
this.logger.error('UpdateClient failed', error.stack || error);
|
||||||
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -529,7 +533,7 @@ export class ManageClientsService {
|
|||||||
const finalBody: UpdateClientContactsDTO = { ...newBody, ...reqBody };
|
const finalBody: UpdateClientContactsDTO = { ...newBody, ...reqBody };
|
||||||
|
|
||||||
let connection;
|
let connection;
|
||||||
let P_cursor_rows = [];
|
let p_cursor_rows: any = [];
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
@ -617,7 +621,7 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
rowsBatch = await cursor.getRows(100);
|
rowsBatch = await cursor.getRows(100);
|
||||||
P_cursor_rows = P_cursor_rows.concat(rowsBatch);
|
p_cursor_rows = p_cursor_rows.concat(rowsBatch);
|
||||||
} while (rowsBatch.length > 0);
|
} while (rowsBatch.length > 0);
|
||||||
|
|
||||||
await cursor.close();
|
await cursor.close();
|
||||||
@ -625,20 +629,24 @@ export class ManageClientsService {
|
|||||||
throw new Error('No cursor returned from the stored procedure');
|
throw new Error('No cursor returned from the stored procedure');
|
||||||
}
|
}
|
||||||
|
|
||||||
return { P_cursor: P_cursor_rows };
|
if (p_cursor_rows[0].ERRORMESG) {
|
||||||
} catch (err) {
|
throw new BadRequestException(p_cursor_rows[0].ERRORMESG);
|
||||||
if (err instanceof Error) {
|
|
||||||
return { error: err.message };
|
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { statusCode: 200, message: "Updated Successfully" };
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof BadRequestException) {
|
||||||
|
this.logger.warn(error.message);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
finally {
|
this.logger.error('UpdateClientContacts failed', error.stack || error);
|
||||||
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -675,7 +683,7 @@ export class ManageClientsService {
|
|||||||
const finalBody: UpdateClientLocationsDTO = { ...newBody, ...reqBody };
|
const finalBody: UpdateClientLocationsDTO = { ...newBody, ...reqBody };
|
||||||
|
|
||||||
let connection;
|
let connection;
|
||||||
let p_cursor_rows = [];
|
let p_cursor_rows: any = [];
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
@ -766,26 +774,31 @@ export class ManageClientsService {
|
|||||||
throw new Error('No cursor returned from the stored procedure');
|
throw new Error('No cursor returned from the stored procedure');
|
||||||
}
|
}
|
||||||
|
|
||||||
return { p_cursor: p_cursor_rows };
|
if (p_cursor_rows[0].ERRORMESG) {
|
||||||
} catch (err) {
|
throw new BadRequestException(p_cursor_rows[0].ERRORMESG);
|
||||||
if (err instanceof Error) {
|
|
||||||
return { error: err.message };
|
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { statusCode: 200, message: "Updated Successfully" };
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof BadRequestException) {
|
||||||
|
this.logger.warn(error.message);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
finally {
|
this.logger.error('UpdateClientLocations failed', error.stack || error);
|
||||||
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CreateClientContact = async (body: CreateAdditionalClientContactsDTO) => {
|
CreateClientContact = async (body: CreateClientContactsDTO) => {
|
||||||
const newBody = {
|
const newBody = {
|
||||||
p_spid: null,
|
p_spid: null,
|
||||||
p_clientid: null,
|
p_clientid: null,
|
||||||
@ -808,18 +821,18 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
setEmptyStringsToNull(reqBody);
|
setEmptyStringsToNull(reqBody);
|
||||||
|
|
||||||
const finalBody: CreateAdditionalClientContactsDTO = {
|
const finalBody: CreateClientContactsDTO = {
|
||||||
...newBody,
|
...newBody,
|
||||||
...reqBody,
|
...reqBody,
|
||||||
};
|
};
|
||||||
|
|
||||||
let connection;
|
let connection;
|
||||||
let p_cursor_rows = [];
|
let p_cursor_rows: any = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw new Error('No DB Connected');
|
throw new InternalServerException('No DB Connected');
|
||||||
}
|
}
|
||||||
|
|
||||||
const CONTACTSTABLE = await connection.getDbObjectClass(
|
const CONTACTSTABLE = await connection.getDbObjectClass(
|
||||||
@ -828,7 +841,7 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
// Check if CONTACTSTABLE is a constructor
|
// Check if CONTACTSTABLE is a constructor
|
||||||
if (typeof CONTACTSTABLE !== 'function') {
|
if (typeof CONTACTSTABLE !== 'function') {
|
||||||
throw new Error('CONTACTSTABLE is not a constructor');
|
throw new InternalServerException('CONTACTSTABLE is not a constructor');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function CREATECONTACTSTABLE_INSTANCE(
|
async function CREATECONTACTSTABLE_INSTANCE(
|
||||||
@ -892,23 +905,23 @@ export class ManageClientsService {
|
|||||||
END;`,
|
END;`,
|
||||||
{
|
{
|
||||||
p_spid: {
|
p_spid: {
|
||||||
val: finalBody.p_spid ? finalBody.p_spid : null,
|
val: finalBody.p_spid,
|
||||||
type: oracledb.DB_TYPE_NUMBER,
|
type: oracledb.DB_TYPE_NUMBER,
|
||||||
},
|
},
|
||||||
p_clientid: {
|
p_clientid: {
|
||||||
val: finalBody.p_clientid ? finalBody.p_clientid : null,
|
val: finalBody.p_clientid,
|
||||||
type: oracledb.DB_TYPE_NUMBER,
|
type: oracledb.DB_TYPE_NUMBER,
|
||||||
},
|
},
|
||||||
p_contactstable: {
|
p_contactstable: {
|
||||||
val: CONTACTSTABLE_INSTANCE,
|
val: CONTACTSTABLE_INSTANCE,
|
||||||
type: oracledb.DB_TYPE_NVARCHAR,
|
type: oracledb.DB_TYPE_OBJECT,
|
||||||
},
|
},
|
||||||
p_defcontactflag: {
|
p_defcontactflag: {
|
||||||
val: finalBody.p_defcontactflag ? finalBody.p_defcontactflag : null,
|
val: finalBody.p_defcontactflag,
|
||||||
type: oracledb.DB_TYPE_NVARCHAR,
|
type: oracledb.DB_TYPE_NVARCHAR,
|
||||||
},
|
},
|
||||||
p_userid: {
|
p_userid: {
|
||||||
val: finalBody.p_userid ? finalBody.p_userid : null,
|
val: finalBody.p_userid,
|
||||||
type: oracledb.DB_TYPE_NVARCHAR,
|
type: oracledb.DB_TYPE_NVARCHAR,
|
||||||
},
|
},
|
||||||
p_cursor: {
|
p_cursor: {
|
||||||
@ -934,34 +947,38 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
await cursor.close();
|
await cursor.close();
|
||||||
} else {
|
} else {
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
throw new InternalServerException('No cursor returned from the stored procedure');
|
||||||
}
|
}
|
||||||
|
|
||||||
return { p_cursor: p_cursor_rows };
|
if (p_cursor_rows[0].ERRORMESG) {
|
||||||
} catch (err) {
|
throw new BadRequestException(p_cursor_rows[0].ERRORMESG);
|
||||||
if (err instanceof Error) {
|
|
||||||
return { error: err.message };
|
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { statusCode: 201, message: "Created Successfully" };
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof BadRequestException) {
|
||||||
|
this.logger.warn(error.message);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
finally {
|
this.logger.error('CreateClientContact failed', error.stack || error);
|
||||||
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CreateClientLocation = async (body: CreateAdditionalClientLocationsDTO) => {
|
CreateClientLocation = async (body: CreateClientLocationsDTO) => {
|
||||||
const newBody = {
|
const newBody = {
|
||||||
p_spid: null,
|
p_spid: null,
|
||||||
p_clientid: null,
|
p_clientid: null,
|
||||||
p_clientlocaddresstable: null,
|
p_clientlocaddresstable: null,
|
||||||
p_defcontactflag: null,
|
|
||||||
p_userid: null,
|
p_userid: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -979,13 +996,13 @@ export class ManageClientsService {
|
|||||||
|
|
||||||
setEmptyStringsToNull(reqBody);
|
setEmptyStringsToNull(reqBody);
|
||||||
|
|
||||||
const finalBody: CreateAdditionalClientLocationsDTO = {
|
const finalBody: CreateClientLocationsDTO = {
|
||||||
...newBody,
|
...newBody,
|
||||||
...reqBody,
|
...reqBody,
|
||||||
};
|
};
|
||||||
|
|
||||||
let connection;
|
let connection;
|
||||||
let p_cursor_rows = [];
|
let p_cursor_rows: any = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
@ -1054,36 +1071,32 @@ export class ManageClientsService {
|
|||||||
MANAGEPREPARER_PKG.CreateClientLocation(
|
MANAGEPREPARER_PKG.CreateClientLocation(
|
||||||
:p_spid,
|
:p_spid,
|
||||||
:p_clientid,
|
:p_clientid,
|
||||||
:p_clientlocaddresstable,
|
:p_ClientLocAddressTable,
|
||||||
:p_defcontactflag,
|
:p_userid,
|
||||||
:p_userid
|
:p_cursor
|
||||||
);
|
);
|
||||||
END;`,
|
END;`,
|
||||||
{
|
{
|
||||||
p_spid: {
|
p_spid: {
|
||||||
val: finalBody.p_spid ? finalBody.p_spid : null,
|
val: finalBody.p_spid,
|
||||||
type: oracledb.DB_TYPE_NUMBER,
|
type: oracledb.DB_TYPE_NUMBER,
|
||||||
},
|
},
|
||||||
p_clientid: {
|
p_clientid: {
|
||||||
val: finalBody.p_clientid ? finalBody.p_clientid : null,
|
val: finalBody.p_clientid,
|
||||||
type: oracledb.DB_TYPE_NUMBER,
|
type: oracledb.DB_TYPE_NUMBER,
|
||||||
},
|
},
|
||||||
p_clientlocaddresstable: {
|
p_clientlocaddresstable: {
|
||||||
val: CLIENTLOCADDRESSTABLE_INSTANCE,
|
val: CLIENTLOCADDRESSTABLE_INSTANCE,
|
||||||
type: oracledb.DB_TYPE_NVARCHAR,
|
type: oracledb.DB_TYPE_OBJECT,
|
||||||
},
|
|
||||||
p_defcontactflag: {
|
|
||||||
val: finalBody.p_defcontactflag ? finalBody.p_defcontactflag : null,
|
|
||||||
type: oracledb.DB_TYPE_NVARCHAR,
|
|
||||||
},
|
},
|
||||||
p_userid: {
|
p_userid: {
|
||||||
val: finalBody.p_userid ? finalBody.p_userid : null,
|
val: finalBody.p_userid,
|
||||||
type: oracledb.DB_TYPE_NVARCHAR,
|
type: oracledb.DB_TYPE_NVARCHAR,
|
||||||
},
|
},
|
||||||
p_cursor: {
|
p_cursor: {
|
||||||
type: oracledb.CURSOR,
|
type: oracledb.CURSOR,
|
||||||
dir: oracledb.BIND_OUT,
|
dir: oracledb.BIND_OUT,
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
||||||
@ -1106,20 +1119,24 @@ export class ManageClientsService {
|
|||||||
throw new Error('No cursor returned from the stored procedure');
|
throw new Error('No cursor returned from the stored procedure');
|
||||||
}
|
}
|
||||||
|
|
||||||
return { p_cursor: p_cursor_rows };
|
if (p_cursor_rows[0].ERRORMESG) {
|
||||||
} catch (err) {
|
throw new BadRequestException(p_cursor_rows[0].ERRORMESG);
|
||||||
if (err instanceof Error) {
|
|
||||||
return { error: err.message };
|
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return { statusCode: 201, message: "Created Successfully" };
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof BadRequestException) {
|
||||||
|
this.logger.warn(error.message);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
finally {
|
this.logger.error('CreateClientLocation failed', error.stack || error);
|
||||||
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1128,13 +1145,13 @@ export class ManageClientsService {
|
|||||||
GetPreparers = async (body: GetPreparersDTO) => {
|
GetPreparers = async (body: GetPreparersDTO) => {
|
||||||
let connection;
|
let connection;
|
||||||
let p_maincursor_rows = [];
|
let p_maincursor_rows = [];
|
||||||
let p_contactscursor_rows = [];
|
// let p_contactscursor_rows = [];
|
||||||
let p_locationcursor_rows = [];
|
// let p_locationcursor_rows = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
throw new Error('No DB Connected');
|
throw new InternalServerException();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await connection.execute(
|
const result = await connection.execute(
|
||||||
@ -1146,9 +1163,7 @@ export class ManageClientsService {
|
|||||||
:p_city,
|
:p_city,
|
||||||
:p_state,
|
:p_state,
|
||||||
:p_status,
|
:p_status,
|
||||||
:p_maincursor,
|
:p_maincursor
|
||||||
:p_contactscursor,
|
|
||||||
:p_locationcursor
|
|
||||||
);
|
);
|
||||||
END;`,
|
END;`,
|
||||||
{
|
{
|
||||||
@ -1179,15 +1194,15 @@ export class ManageClientsService {
|
|||||||
p_maincursor: {
|
p_maincursor: {
|
||||||
type: oracledb.CURSOR,
|
type: oracledb.CURSOR,
|
||||||
dir: oracledb.BIND_OUT,
|
dir: oracledb.BIND_OUT,
|
||||||
},
|
}
|
||||||
p_contactscursor: {
|
// p_contactscursor: {
|
||||||
type: oracledb.CURSOR,
|
// type: oracledb.CURSOR,
|
||||||
dir: oracledb.BIND_OUT,
|
// dir: oracledb.BIND_OUT,
|
||||||
},
|
// },
|
||||||
p_locationcursor: {
|
// p_locationcursor: {
|
||||||
type: oracledb.CURSOR,
|
// type: oracledb.CURSOR,
|
||||||
dir: oracledb.BIND_OUT,
|
// dir: oracledb.BIND_OUT,
|
||||||
},
|
// },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
||||||
@ -1206,47 +1221,45 @@ export class ManageClientsService {
|
|||||||
await cursor.close();
|
await cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.outBinds && result.outBinds.p_contactscursor) {
|
// if (result.outBinds && result.outBinds.p_contactscursor) {
|
||||||
const cursor = result.outBinds.p_contactscursor;
|
// const cursor = result.outBinds.p_contactscursor;
|
||||||
let rowsBatch;
|
// let rowsBatch;
|
||||||
|
|
||||||
do {
|
// do {
|
||||||
rowsBatch = await cursor.getRows(100);
|
// rowsBatch = await cursor.getRows(100);
|
||||||
p_contactscursor_rows = p_contactscursor_rows.concat(rowsBatch);
|
// p_contactscursor_rows = p_contactscursor_rows.concat(rowsBatch);
|
||||||
} while (rowsBatch.length > 0);
|
// } while (rowsBatch.length > 0);
|
||||||
|
|
||||||
await cursor.close();
|
// await cursor.close();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (result.outBinds && result.outBinds.p_locationcursor) {
|
||||||
|
// const cursor = result.outBinds.p_locationcursor;
|
||||||
|
// let rowsBatch;
|
||||||
|
|
||||||
|
// do {
|
||||||
|
// rowsBatch = await cursor.getRows(100);
|
||||||
|
// p_locationcursor_rows = p_locationcursor_rows.concat(rowsBatch);
|
||||||
|
// } while (rowsBatch.length > 0);
|
||||||
|
|
||||||
|
// await cursor.close();
|
||||||
|
// }
|
||||||
|
|
||||||
|
return p_maincursor_rows;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof BadRequestException) {
|
||||||
|
this.logger.warn(error.message);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
this.logger.error('GetPreparers failed', error.stack || error);
|
||||||
if (result.outBinds && result.outBinds.p_locationcursor) {
|
throw new InternalServerException();
|
||||||
const cursor = result.outBinds.p_locationcursor;
|
} finally {
|
||||||
let rowsBatch;
|
|
||||||
|
|
||||||
do {
|
|
||||||
rowsBatch = await cursor.getRows(100);
|
|
||||||
p_locationcursor_rows = p_locationcursor_rows.concat(rowsBatch);
|
|
||||||
} while (rowsBatch.length > 0);
|
|
||||||
|
|
||||||
await cursor.close();
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
p_maincursor: p_maincursor_rows,
|
|
||||||
p_contactscursor: p_contactscursor_rows,
|
|
||||||
p_locationcursor: p_locationcursor_rows,
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
if (err instanceof Error) {
|
|
||||||
return { error: err.message };
|
|
||||||
} else {
|
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1256,7 +1269,7 @@ export class ManageClientsService {
|
|||||||
body: GetPreparerByClientidContactsByClientidLocByClientidDTO,
|
body: GetPreparerByClientidContactsByClientidLocByClientidDTO,
|
||||||
) => {
|
) => {
|
||||||
let connection;
|
let connection;
|
||||||
let p_cursor_rows = [];
|
let p_cursor_rows: any = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection = await this.oracleDBService.getConnection();
|
connection = await this.oracleDBService.getConnection();
|
||||||
@ -1303,20 +1316,21 @@ export class ManageClientsService {
|
|||||||
await cursor.close();
|
await cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return { p_cursor: p_cursor_rows };
|
return p_cursor_rows;
|
||||||
} catch (err) {
|
|
||||||
if (err instanceof Error) {
|
} catch (error) {
|
||||||
return { error: err.message };
|
if (error instanceof BadRequestException) {
|
||||||
} else {
|
this.logger.warn(error.message);
|
||||||
return { error: 'An unknown error occurred' };
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
this.logger.error('GetPreparerByClientid failed', error.stack || error);
|
||||||
finally {
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1373,20 +1387,20 @@ export class ManageClientsService {
|
|||||||
await cursor.close();
|
await cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return { p_cursor: p_cursor_rows };
|
return p_cursor_rows;
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
if (err instanceof Error) {
|
if (error instanceof BadRequestException) {
|
||||||
return { error: err.message };
|
this.logger.warn(error.message);
|
||||||
} else {
|
throw error;
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
}
|
this.logger.error('GetPreparerContactsByClientid failed', error.stack || error);
|
||||||
finally {
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1443,20 +1457,20 @@ export class ManageClientsService {
|
|||||||
await cursor.close();
|
await cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return { p_cursor: p_cursor_rows };
|
return p_cursor_rows;
|
||||||
} catch (err) {
|
} catch (error) {
|
||||||
if (err instanceof Error) {
|
if (error instanceof BadRequestException) {
|
||||||
return { error: err.message };
|
this.logger.warn(error.message);
|
||||||
} else {
|
throw error;
|
||||||
return { error: 'An unknown error occurred' };
|
|
||||||
}
|
}
|
||||||
}
|
this.logger.error('GetPreparerLocByClientid failed', error.stack || error);
|
||||||
finally {
|
throw new InternalServerException();
|
||||||
|
} finally {
|
||||||
if (connection) {
|
if (connection) {
|
||||||
try {
|
try {
|
||||||
await connection.close();
|
await connection.close();
|
||||||
} catch (closeErr) {
|
} catch (closeErr) {
|
||||||
console.error('Failed to close connection:', closeErr);
|
this.logger.error('Failed to close DB connection', closeErr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,6 @@ export class RegionController {
|
|||||||
// @ApiTags('Regions - Oracle')
|
// @ApiTags('Regions - Oracle')
|
||||||
// @Get('/getDetails')
|
// @Get('/getDetails')
|
||||||
selectAll() {
|
selectAll() {
|
||||||
return this.regionService.selectAll();
|
return this.regionService.selectSP();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,6 +42,56 @@ export class RegionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async selectSP() {
|
||||||
|
let connection: oracledb.Connection | undefined;
|
||||||
|
try {
|
||||||
|
connection = await this.oracleDBService.getConnection();
|
||||||
|
if (!connection) {
|
||||||
|
throw new InternalServerException();
|
||||||
|
}
|
||||||
|
|
||||||
|
// const result = await connection.execute(
|
||||||
|
// `
|
||||||
|
// SELECT text
|
||||||
|
// FROM all_source
|
||||||
|
// WHERE name = 'MANAGEPREPARER_PKG' AND type = 'PACKAGE BODY'
|
||||||
|
// ORDER BY line
|
||||||
|
// `,
|
||||||
|
// [],
|
||||||
|
// {
|
||||||
|
// outFormat: oracledb.OUT_FORMAT_OBJECT,
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
|
const result: any = await connection.execute(
|
||||||
|
`SELECT text
|
||||||
|
FROM all_source
|
||||||
|
WHERE name = :pkgName AND type = 'PACKAGE BODY'
|
||||||
|
ORDER BY line`,
|
||||||
|
{ pkgName: 'MANAGEPREPARER_PKG' }, // bind variable
|
||||||
|
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(result);
|
||||||
|
|
||||||
|
const sourceCode = result.rows.map(row => row.TEXT).join('');
|
||||||
|
console.log(sourceCode);
|
||||||
|
return sourceCode;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error('selectAll 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) {
|
async insertRegions(body: InsertRegionsDto) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user