modified client api
This commit is contained in:
parent
7d97c9b0b6
commit
aff1e69dec
@ -1,28 +1,87 @@
|
||||
import { MssqlConfig, OracleConfig } from 'ormconfig';
|
||||
import { createPool, Pool, Connection as cob } from 'oracledb';
|
||||
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()
|
||||
export class OracleDBService {
|
||||
private pool: Pool;
|
||||
private pool: Pool | null = null;
|
||||
|
||||
private readonly logger = new Logger(OracleDBService.name);
|
||||
|
||||
constructor() {
|
||||
this.initializePool();
|
||||
}
|
||||
|
||||
private async initializePool() {
|
||||
this.pool = await createPool({
|
||||
...OracleConfig,
|
||||
poolMin: 1,
|
||||
poolMax: 10,
|
||||
poolIncrement: 1,
|
||||
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(): Promise<void> {
|
||||
try {
|
||||
this.pool = await createPool({
|
||||
...OracleConfig,
|
||||
poolMin: 1,
|
||||
poolMax: 10,
|
||||
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> {
|
||||
const connection = await this.pool.getConnection();
|
||||
return connection;
|
||||
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();
|
||||
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 { ManageClientsService } from './manage-clients.service';
|
||||
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')
|
||||
export class ManageClientsController {
|
||||
@ -33,13 +33,13 @@ export class ManageClientsController {
|
||||
|
||||
@ApiTags('Manage Clients - Mssql')
|
||||
@Post('CreateAdditionalClientContacts')
|
||||
CreateClientContact(@Body() body: CreateAdditionalClientContactsDTO) {
|
||||
CreateClientContact(@Body() body: CreateClientContactsDTO) {
|
||||
return this.manageClientsService.CreateClientContact(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Mssql')
|
||||
@Post('CreateAdditionalClientLocations')
|
||||
CreateClientLocation(@Body() body: CreateAdditionalClientLocationsDTO) {
|
||||
CreateClientLocation(@Body() body: CreateClientLocationsDTO) {
|
||||
return this.manageClientsService.CreateClientLocation(body);
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Connection, Request } from 'mssql';
|
||||
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';
|
||||
|
||||
@Injectable()
|
||||
@ -70,18 +70,18 @@ export class ManageClientsService {
|
||||
contactTable.columns.add('MobileNo', mssql.VarChar(20));
|
||||
contactTable.columns.add('FaxNo', mssql.VarChar(20));
|
||||
|
||||
finalBody.p_contactstable.forEach((contact) => {
|
||||
contactTable.rows.add(
|
||||
contact.FirstName,
|
||||
contact.LastName,
|
||||
contact.MiddleInitial,
|
||||
contact.Title,
|
||||
contact.EmailAddress,
|
||||
contact.PhoneNo,
|
||||
contact.MobileNo,
|
||||
contact.FaxNo,
|
||||
);
|
||||
});
|
||||
// finalBody.p_contactstable.forEach((contact) => {
|
||||
// contactTable.rows.add(
|
||||
// contact.FirstName,
|
||||
// contact.LastName,
|
||||
// contact.MiddleInitial,
|
||||
// contact.Title,
|
||||
// contact.EmailAddress,
|
||||
// contact.PhoneNo,
|
||||
// contact.MobileNo,
|
||||
// contact.FaxNo,
|
||||
// );
|
||||
// });
|
||||
|
||||
request.input('p_contactstable', contactTable);
|
||||
|
||||
@ -95,17 +95,17 @@ export class ManageClientsService {
|
||||
clientLocAddressTable.columns.add('Zip', mssql.VarChar(10));
|
||||
clientLocAddressTable.columns.add('Country', mssql.VarChar(2));
|
||||
|
||||
finalBody.p_clientlocaddresstable.forEach((contact) => {
|
||||
clientLocAddressTable.rows.add(
|
||||
contact.Nameof,
|
||||
contact.Address1,
|
||||
contact.Address2,
|
||||
contact.City,
|
||||
contact.State,
|
||||
contact.Zip,
|
||||
contact.Country,
|
||||
);
|
||||
});
|
||||
// finalBody.p_clientlocaddresstable.forEach((contact) => {
|
||||
// clientLocAddressTable.rows.add(
|
||||
// contact.Nameof,
|
||||
// contact.Address1,
|
||||
// contact.Address2,
|
||||
// contact.City,
|
||||
// contact.State,
|
||||
// contact.Zip,
|
||||
// contact.Country,
|
||||
// );
|
||||
// });
|
||||
|
||||
request.input('p_clientlocaddresstable', clientLocAddressTable);
|
||||
|
||||
@ -188,7 +188,7 @@ export class ManageClientsService {
|
||||
}
|
||||
};
|
||||
|
||||
CreateClientContact = async (body: CreateAdditionalClientContactsDTO) => {
|
||||
CreateClientContact = async (body: CreateClientContactsDTO) => {
|
||||
const newBody = {
|
||||
p_spid: null,
|
||||
p_clientid: null,
|
||||
@ -211,7 +211,7 @@ export class ManageClientsService {
|
||||
|
||||
setEmptyStringsToNull(reqBody);
|
||||
|
||||
const finalBody: CreateAdditionalClientContactsDTO = {
|
||||
const finalBody: CreateClientContactsDTO = {
|
||||
...newBody,
|
||||
...reqBody,
|
||||
};
|
||||
@ -371,7 +371,7 @@ export class ManageClientsService {
|
||||
|
||||
};
|
||||
|
||||
CreateClientLocation = async (body: CreateAdditionalClientLocationsDTO) => {
|
||||
CreateClientLocation = async (body: CreateClientLocationsDTO) => {
|
||||
const newBody = {
|
||||
p_spid: null,
|
||||
p_clientid: null,
|
||||
@ -394,7 +394,7 @@ export class ManageClientsService {
|
||||
|
||||
setEmptyStringsToNull(reqBody);
|
||||
|
||||
const finalBody: CreateAdditionalClientLocationsDTO = {
|
||||
const finalBody: CreateClientLocationsDTO = {
|
||||
...newBody,
|
||||
...reqBody,
|
||||
};
|
||||
@ -431,7 +431,6 @@ export class ManageClientsService {
|
||||
|
||||
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);
|
||||
|
||||
const result = await request.execute('carnetsys.CreateClientLocation');
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||
import { ManageClientsService } from './manage-clients.service';
|
||||
import {
|
||||
CreateAdditionalClientContactsDTO,
|
||||
CreateAdditionalClientLocationsDTO,
|
||||
CreateClientContactsDTO,
|
||||
CreateClientDataDTO,
|
||||
CreateClientLocationsDTO,
|
||||
GetPreparerByClientidContactsByClientidLocByClientidDTO,
|
||||
GetPreparersDTO,
|
||||
UpdateClientContactsDTO,
|
||||
@ -41,14 +41,14 @@ export class ManageClientsController {
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Post('CreateAdditionalClientContacts')
|
||||
CreateClientContact(@Body() body: CreateAdditionalClientContactsDTO) {
|
||||
@Post('CreateClientContacts')
|
||||
CreateClientContact(@Body() body: CreateClientContactsDTO) {
|
||||
return this.manageClientsService.CreateClientContact(body);
|
||||
}
|
||||
|
||||
@ApiTags('Manage Clients - Oracle')
|
||||
@Post('CreateAdditionalClientLocations')
|
||||
CreateClientLocation(@Body() body: CreateAdditionalClientLocationsDTO) {
|
||||
@Post('CreateClientLocations')
|
||||
CreateClientLocation(@Body() body: CreateClientLocationsDTO) {
|
||||
return this.manageClientsService.CreateClientLocation(body);
|
||||
}
|
||||
|
||||
|
||||
@ -171,21 +171,21 @@ export class CreateClientDataDTO {
|
||||
@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_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[];
|
||||
// @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 {
|
||||
@ -508,7 +508,7 @@ export class UpdateClientLocationsDTO {
|
||||
p_userid: string;
|
||||
}
|
||||
|
||||
export class CreateAdditionalClientContactsDTO {
|
||||
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' })
|
||||
@ -549,7 +549,7 @@ export class CreateAdditionalClientContactsDTO {
|
||||
p_userid: string;
|
||||
}
|
||||
|
||||
export class CreateAdditionalClientLocationsDTO {
|
||||
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' })
|
||||
@ -575,13 +575,13 @@ export class CreateAdditionalClientLocationsDTO {
|
||||
@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, 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, {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -30,6 +30,6 @@ export class RegionController {
|
||||
// @ApiTags('Regions - Oracle')
|
||||
// @Get('/getDetails')
|
||||
selectAll() {
|
||||
return this.regionService.selectAll();
|
||||
return this.regionService.selectSP();
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ export class RegionService {
|
||||
if (!connection) {
|
||||
throw new InternalServerException();
|
||||
}
|
||||
|
||||
|
||||
const result = await connection.execute(
|
||||
`SELECT * FROM BasicFeeSetup`,
|
||||
[],
|
||||
@ -26,7 +26,7 @@ export class RegionService {
|
||||
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
return result.rows;
|
||||
} catch (error) {
|
||||
this.logger.error('selectAll failed', error.stack || error);
|
||||
@ -41,8 +41,58 @@ 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) {
|
||||
let connection;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user