proj with persistent connection pool
This commit is contained in:
parent
dee205a8ad
commit
6f7e1229a0
23
api.http
Normal file
23
api.http
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
GET http://localhost:3000/oracle/GetRegions
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
POST http://localhost:3000/oracle/InsertRegions
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"p_region":"p_region",
|
||||||
|
"p_name":"p_name"
|
||||||
|
}
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
|
PATCH http://localhost:3000/oracle/UpdateRegion
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"p_regionID": ,
|
||||||
|
"p_name":"p_name"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
26
ormconfig.ts
26
ormconfig.ts
@ -1,24 +1,24 @@
|
|||||||
import { DataSourceOptions } from 'typeorm';
|
import { DataSourceOptions } from 'typeorm';
|
||||||
|
|
||||||
export const OracleConfig: any = {
|
export const OracleConfig: any = {
|
||||||
type: 'oracle',
|
// type: 'oracle',
|
||||||
username: 'system',
|
user: 'Carnetsys',
|
||||||
password: 'root',
|
password: 'Carnet1234',
|
||||||
connectString: '192.168.1.96/xe',
|
connectString: '172.31.18.76/xe',
|
||||||
// entities: [__dirname + '/**/*.entity{.ts,.js}'],
|
// entities: [__dirname + '/**/*.entity{.ts,.js}'],
|
||||||
// synchronize: true,
|
// synchronize: true,
|
||||||
autoCommit: true
|
// autoCommit: true
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MssqlConfig: DataSourceOptions = {
|
export const MssqlConfig: any = {
|
||||||
type: 'mssql',
|
// type: 'mssql',
|
||||||
host: 'localhost',
|
host: '172.31.18.76',
|
||||||
port: 1433,
|
// port: 1433,
|
||||||
username: 'mssql1433',
|
user: 'Carnetsys',
|
||||||
password: 'root',
|
password: 'Carnet1234',
|
||||||
database: 'demo',
|
database: 'CarnetDB',
|
||||||
// entities: [__dirname + '/**/*.entity{.ts,.js}'],
|
// entities: [__dirname + '/**/*.entity{.ts,.js}'],
|
||||||
synchronize: true,
|
// synchronize: true,
|
||||||
options: {
|
options: {
|
||||||
enableArithAbort: true,
|
enableArithAbort: true,
|
||||||
trustServerCertificate: true,
|
trustServerCertificate: true,
|
||||||
|
|||||||
53
package-lock.json
generated
53
package-lock.json
generated
@ -13,6 +13,8 @@
|
|||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"@nestjs/platform-express": "^11.0.1",
|
||||||
"@nestjs/typeorm": "^11.0.0",
|
"@nestjs/typeorm": "^11.0.0",
|
||||||
|
"class-transformer": "^0.5.1",
|
||||||
|
"class-validator": "^0.14.1",
|
||||||
"mssql": "^10.0.4",
|
"mssql": "^10.0.4",
|
||||||
"mysql2": "^3.12.0",
|
"mysql2": "^3.12.0",
|
||||||
"oracledb": "^6.7.2",
|
"oracledb": "^6.7.2",
|
||||||
@ -31,6 +33,7 @@
|
|||||||
"@swc/core": "^1.10.7",
|
"@swc/core": "^1.10.7",
|
||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
|
"@types/mssql": "^9.1.7",
|
||||||
"@types/node": "^22.10.7",
|
"@types/node": "^22.10.7",
|
||||||
"@types/oracledb": "^6.5.3",
|
"@types/oracledb": "^6.5.3",
|
||||||
"@types/supertest": "^6.0.2",
|
"@types/supertest": "^6.0.2",
|
||||||
@ -3415,6 +3418,18 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/mssql": {
|
||||||
|
"version": "9.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/mssql/-/mssql-9.1.7.tgz",
|
||||||
|
"integrity": "sha512-eIOEe78nuSW5KctDHImDhLZ9a+jV/z/Xs5RBhcG/jrk+YWqhdNmzBmHVWV7aWQ5fW+jbIGtX6Ph+bbVqfhzafg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*",
|
||||||
|
"tarn": "^3.0.1",
|
||||||
|
"tedious": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "22.13.4",
|
"version": "22.13.4",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.4.tgz",
|
||||||
@ -3518,6 +3533,12 @@
|
|||||||
"@types/superagent": "^8.1.0"
|
"@types/superagent": "^8.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/validator": {
|
||||||
|
"version": "13.12.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.12.2.tgz",
|
||||||
|
"integrity": "sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/yargs": {
|
"node_modules/@types/yargs": {
|
||||||
"version": "17.0.33",
|
"version": "17.0.33",
|
||||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz",
|
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz",
|
||||||
@ -5080,6 +5101,23 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/class-transformer": {
|
||||||
|
"version": "0.5.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz",
|
||||||
|
"integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/class-validator": {
|
||||||
|
"version": "0.14.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.1.tgz",
|
||||||
|
"integrity": "sha512-2VEG9JICxIqTpoK1eMzZqaV+u/EiwEJkMGzTrZf6sU/fwsnOITVgYJ8yojSy6CaXtO9V0Cc6ZQZ8h8m4UBuLwQ==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@types/validator": "^13.11.8",
|
||||||
|
"libphonenumber-js": "^1.10.53",
|
||||||
|
"validator": "^13.9.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/cli-cursor": {
|
"node_modules/cli-cursor": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
|
||||||
@ -9291,6 +9329,12 @@
|
|||||||
"node": ">= 0.8.0"
|
"node": ">= 0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/libphonenumber-js": {
|
||||||
|
"version": "1.11.20",
|
||||||
|
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.11.20.tgz",
|
||||||
|
"integrity": "sha512-/ipwAMvtSZRdiQBHqW1qxqeYiBMzncOQLVA+62MWYr7N4m7Q2jqpJ0WgT7zlOEOpyLRSqrMXidbJpC0J77AaKA==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/lines-and-columns": {
|
"node_modules/lines-and-columns": {
|
||||||
"version": "1.2.4",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
|
||||||
@ -13304,6 +13348,15 @@
|
|||||||
"node": ">=10.12.0"
|
"node": ">=10.12.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/validator": {
|
||||||
|
"version": "13.12.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz",
|
||||||
|
"integrity": "sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/vary": {
|
"node_modules/vary": {
|
||||||
"version": "1.1.2",
|
"version": "1.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
|
||||||
|
|||||||
@ -24,6 +24,8 @@
|
|||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.0.1",
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"@nestjs/platform-express": "^11.0.1",
|
||||||
"@nestjs/typeorm": "^11.0.0",
|
"@nestjs/typeorm": "^11.0.0",
|
||||||
|
"class-transformer": "^0.5.1",
|
||||||
|
"class-validator": "^0.14.1",
|
||||||
"mssql": "^10.0.4",
|
"mssql": "^10.0.4",
|
||||||
"mysql2": "^3.12.0",
|
"mysql2": "^3.12.0",
|
||||||
"oracledb": "^6.7.2",
|
"oracledb": "^6.7.2",
|
||||||
@ -42,6 +44,7 @@
|
|||||||
"@swc/core": "^1.10.7",
|
"@swc/core": "^1.10.7",
|
||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
|
"@types/mssql": "^9.1.7",
|
||||||
"@types/node": "^22.10.7",
|
"@types/node": "^22.10.7",
|
||||||
"@types/oracledb": "^6.5.3",
|
"@types/oracledb": "^6.5.3",
|
||||||
"@types/supertest": "^6.0.2",
|
"@types/supertest": "^6.0.2",
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { AppController } from './app.controller';
|
|
||||||
import { AppService } from './app.service';
|
|
||||||
|
|
||||||
describe('AppController', () => {
|
|
||||||
let appController: AppController;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const app: TestingModule = await Test.createTestingModule({
|
|
||||||
controllers: [AppController],
|
|
||||||
providers: [AppService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
appController = app.get<AppController>(AppController);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('root', () => {
|
|
||||||
it('should return "Hello World!"', () => {
|
|
||||||
expect(appController.getHello()).toBe('Hello World!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -2,10 +2,10 @@ import { Module } from '@nestjs/common';
|
|||||||
import { AppController } from './app.controller';
|
import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
import { DbModule } from './db/db.module';
|
import { DbModule } from './db/db.module';
|
||||||
import { OracleSpModule } from './oraclesp/oraclesp.module';
|
import { OracleModule } from './oracle/oracle.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [DbModule, OracleSpModule],
|
imports: [DbModule, OracleModule],
|
||||||
controllers: [AppController],
|
controllers: [AppController],
|
||||||
providers: [AppService],
|
providers: [AppService],
|
||||||
})
|
})
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { DbController } from './db.controller';
|
|
||||||
|
|
||||||
describe('DbController', () => {
|
|
||||||
let controller: DbController;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
controllers: [DbController],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
controller = module.get<DbController>(DbController);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(controller).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
import { Controller, Get, Param } from '@nestjs/common';
|
|
||||||
import { DbService } from './db.service';
|
|
||||||
|
|
||||||
@Controller('db')
|
|
||||||
export class DbController {
|
|
||||||
constructor(private readonly dbService: DbService) { }
|
|
||||||
|
|
||||||
@Get('/getConn/:type')
|
|
||||||
async getConn(@Param('type') type: string) {
|
|
||||||
try {
|
|
||||||
const dataSource = this.dbService.getDataSource();
|
|
||||||
if (dataSource) {
|
|
||||||
return 'Connection successfull1';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
await this.dbService.initialize(this.dbService.getDbTypeConfig(type))
|
|
||||||
const conn = this.dbService.getDataSource();
|
|
||||||
if(conn){
|
|
||||||
return "Connection successfull2";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new Error('Error while connecting to db..!')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get('/closeConn')
|
|
||||||
closeConn() {
|
|
||||||
try {
|
|
||||||
const dataSource = this.dbService.getDataSource();
|
|
||||||
if (dataSource) {
|
|
||||||
return this.dbService.closeConnection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
return "No Connection Detected to close";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,10 +1,8 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { DbService } from './db.service';
|
import { MssqlDBService, OracleDBService } from './db.service';
|
||||||
import { DbController } from './db.controller';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [DbService],
|
providers: [OracleDBService,MssqlDBService],
|
||||||
controllers: [DbController],
|
exports:[OracleDBService,MssqlDBService]
|
||||||
exports:[DbService]
|
|
||||||
})
|
})
|
||||||
export class DbModule {}
|
export class DbModule {}
|
||||||
|
|||||||
@ -1,18 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { DbService } from './db.service';
|
|
||||||
|
|
||||||
describe('DbService', () => {
|
|
||||||
let service: DbService;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
providers: [DbService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
service = module.get<DbService>(DbService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(service).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,54 +1,59 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { MssqlConfig , OracleConfig} from 'ormconfig';
|
import { MssqlConfig , OracleConfig} from 'ormconfig';
|
||||||
import { DataSource, DataSourceOptions } from 'typeorm';
|
import { createPool, Pool, Connection as cob, } from 'oracledb';
|
||||||
import * as oracledb from 'oracledb';
|
import { Connection, ConnectionPool } from 'mssql';
|
||||||
|
|
||||||
@Injectable()
|
export class OracleDBService {
|
||||||
export class DbService {
|
private pool: Pool;
|
||||||
private dataSource: DataSource | null = null;
|
|
||||||
private oracleConnection: oracledb.Connection | null = null;
|
|
||||||
|
|
||||||
constructor() {}
|
constructor() {
|
||||||
|
this.initializePool();
|
||||||
|
}
|
||||||
|
|
||||||
async initialize(options: DataSourceOptions) {
|
private async initializePool() {
|
||||||
if (options.type === 'oracle') {
|
this.pool = await createPool({
|
||||||
this.oracleConnection = await oracledb.getConnection(options);
|
...OracleConfig,
|
||||||
} else {
|
poolMin: 1,
|
||||||
this.dataSource = new DataSource({
|
poolMax: 10,
|
||||||
...options,
|
poolIncrement: 1,
|
||||||
});
|
});
|
||||||
await this.dataSource.initialize();
|
}
|
||||||
console.log('Data Source has been initialized!');
|
|
||||||
|
async getConnection(): Promise<cob> {
|
||||||
|
const connection = await this.pool.getConnection();
|
||||||
|
console.log('Database connection initialized successfully for oracle.');
|
||||||
|
return connection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getDataSource(): DataSource | oracledb.Connection | null {
|
export class MssqlDBService {
|
||||||
if (this.oracleConnection) {
|
private pool: ConnectionPool;
|
||||||
return this.oracleConnection; // Return the Oracle connection
|
private readonly config = {
|
||||||
}
|
...MssqlConfig,
|
||||||
return this.dataSource; // Return the TypeORM DataSource
|
server: "localhost",
|
||||||
|
pool: {
|
||||||
|
max: 10,
|
||||||
|
min: 0,
|
||||||
|
idleTimeoutMillis: 30000,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.initializePool();
|
||||||
}
|
}
|
||||||
|
|
||||||
getDbTypeConfig(type?: string): DataSourceOptions {
|
private async initializePool() {
|
||||||
if (type === 'oracle') return OracleConfig;
|
this.pool = new ConnectionPool(this.config);
|
||||||
else return MssqlConfig;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async closeConnection() {
|
async getConnection(): Promise<Connection> {
|
||||||
if (this.oracleConnection) {
|
|
||||||
try {
|
try {
|
||||||
await this.oracleConnection.close(); // Close Oracle connection
|
const connection = await this.pool.connect();
|
||||||
console.log('Oracle connection has been closed!');
|
console.log('Database connection initialized successfully for Mssql.');
|
||||||
} catch (err) {
|
// console.log(`Connection established to server: ${this.config.server}`); // Log server info
|
||||||
console.error('Error closing Oracle connection:', err);
|
return connection;
|
||||||
}
|
} catch (error) {
|
||||||
this.oracleConnection = null;
|
console.error('Error getting connection from pool', error.stack);
|
||||||
} else if (this.dataSource) {
|
throw error; // Rethrow the error after logging
|
||||||
await this.dataSource.destroy();
|
|
||||||
console.log('Data Source has been closed!');
|
|
||||||
this.dataSource = null;
|
|
||||||
} else {
|
|
||||||
console.log('Data Source is not initialized.');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,8 +1,10 @@
|
|||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
import { ValidationPipe } from '@nestjs/common';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
app.useGlobalPipes(new ValidationPipe());
|
||||||
await app.listen(process.env.PORT ?? 3000);
|
await app.listen(process.env.PORT ?? 3000);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
23
src/oracle/oracle.controller.ts
Normal file
23
src/oracle/oracle.controller.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { Body, Controller, Get, Patch, Post } from '@nestjs/common';
|
||||||
|
import { OracleService } from './oracle.service';
|
||||||
|
import { InsertRegionsDto, UpdateRegionDto } from './oracle.dto';
|
||||||
|
|
||||||
|
@Controller('oracle')
|
||||||
|
export class OracleController {
|
||||||
|
constructor(private readonly oarcleService: OracleService) { }
|
||||||
|
|
||||||
|
@Get('/GetRegions')
|
||||||
|
getRegions() {
|
||||||
|
return this.oarcleService.getRegions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post('/InsertRegions')
|
||||||
|
insertRegions(@Body() body: InsertRegionsDto) {
|
||||||
|
return this.oarcleService.insertRegions(body.p_region, body.p_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch('/UpdateRegion')
|
||||||
|
updateRegions(@Body() body: UpdateRegionDto) {
|
||||||
|
return this.oarcleService.updateRegions(body.p_regionID,body.p_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/oracle/oracle.dto.ts
Normal file
18
src/oracle/oracle.dto.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { IsNumber, IsString } from 'class-validator';
|
||||||
|
|
||||||
|
export class InsertRegionsDto {
|
||||||
|
@IsString()
|
||||||
|
p_region: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
p_name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class UpdateRegionDto {
|
||||||
|
@IsNumber()
|
||||||
|
p_regionID: number;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
p_name: string;
|
||||||
|
}
|
||||||
|
|
||||||
13
src/oracle/oracle.module.ts
Normal file
13
src/oracle/oracle.module.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { OracleService } from './oracle.service';
|
||||||
|
import { OracleController } from './oracle.controller';
|
||||||
|
import { OracleDBService } from 'src/db/db.service';
|
||||||
|
import { DbModule } from 'src/db/db.module';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports:[DbModule],
|
||||||
|
providers: [OracleService],
|
||||||
|
controllers: [OracleController],
|
||||||
|
exports:[OracleService]
|
||||||
|
})
|
||||||
|
export class OracleModule {}
|
||||||
144
src/oracle/oracle.service.ts
Normal file
144
src/oracle/oracle.service.ts
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { OracleDBService } from 'src/db/db.service';
|
||||||
|
import * as oracledb from 'oracledb'
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class OracleService {
|
||||||
|
constructor(private readonly oracleDBService: OracleDBService) { }
|
||||||
|
|
||||||
|
async getRegions() {
|
||||||
|
let connection;
|
||||||
|
let rows = [];
|
||||||
|
try {
|
||||||
|
connection = await this.oracleDBService.getConnection()
|
||||||
|
if (!connection) {
|
||||||
|
throw new Error('No DB Connected')
|
||||||
|
}
|
||||||
|
|
||||||
|
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; // The OUT cursor
|
||||||
|
let rowsBatch;
|
||||||
|
|
||||||
|
do {
|
||||||
|
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
||||||
|
rows = rows.concat(rowsBatch); // Append fetched rows to the main array
|
||||||
|
} while (rowsBatch.length > 0);
|
||||||
|
|
||||||
|
console.log('Rows fetched:', rows);
|
||||||
|
|
||||||
|
// Close the cursor after you're done
|
||||||
|
await cursor.close();
|
||||||
|
} else {
|
||||||
|
throw new Error('No cursor returned from the stored procedure');
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching users: ', err);
|
||||||
|
throw new Error('Error fetching users');
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async insertRegions(p_region: String, p_name: String) {
|
||||||
|
let connection;
|
||||||
|
try {
|
||||||
|
// Connect to the Oracle database using oracledb
|
||||||
|
connection = await this.oracleDBService.getConnection()
|
||||||
|
if (!connection) {
|
||||||
|
throw new Error('No DB Connected')
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await connection.execute(
|
||||||
|
`BEGIN
|
||||||
|
sp1(:p_region,:p_name,:p_cursor);
|
||||||
|
END;`, {
|
||||||
|
p_region: {
|
||||||
|
val: p_region,
|
||||||
|
type: oracledb.DB_TYPE_VARCHAR
|
||||||
|
},
|
||||||
|
p_name: {
|
||||||
|
val: p_name,
|
||||||
|
type: oracledb.DB_TYPE_VARCHAR
|
||||||
|
},
|
||||||
|
p_cursor: {
|
||||||
|
type: oracledb.CURSOR,
|
||||||
|
dir: oracledb.BIND_OUT
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
outFormat: oracledb.OUT_FORMAT_OBJECT
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await connection.commit();
|
||||||
|
|
||||||
|
let fres = await result.outBinds.p_cursor.getRows();
|
||||||
|
|
||||||
|
return fres
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching users: ', err);
|
||||||
|
throw new Error('Error fetching users');
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async updateRegions(p_regionID: Number, p_name: String) {
|
||||||
|
let connection;
|
||||||
|
try {
|
||||||
|
// Connect to the Oracle database using oracledb
|
||||||
|
connection = await this.oracleDBService.getConnection()
|
||||||
|
if (!connection) {
|
||||||
|
throw new Error('No DB Connected')
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await connection.execute(
|
||||||
|
`BEGIN
|
||||||
|
sp1(:p_regionID,:p_name,:p_cursor);
|
||||||
|
END;`, {
|
||||||
|
p_regionID: {
|
||||||
|
val: p_regionID,
|
||||||
|
type: oracledb.DB_TYPE_NUMBER
|
||||||
|
},
|
||||||
|
p_name: {
|
||||||
|
val: p_name,
|
||||||
|
type: oracledb.DB_TYPE_VARCHAR
|
||||||
|
},
|
||||||
|
p_cursor: {
|
||||||
|
type: oracledb.CURSOR,
|
||||||
|
dir: oracledb.BIND_OUT
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
outFormat: oracledb.OUT_FORMAT_OBJECT
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
await connection.commit();
|
||||||
|
|
||||||
|
let fres = await result.outBinds.p_cursor.getRows();
|
||||||
|
|
||||||
|
return fres
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching users: ', err);
|
||||||
|
throw new Error('Error fetching users');
|
||||||
|
} finally {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import { Controller,Get } from '@nestjs/common';
|
|
||||||
import { OracleSpService } from './oraclesp.service';
|
|
||||||
|
|
||||||
@Controller('oracleSP')
|
|
||||||
export class OracleSpController {
|
|
||||||
constructor(private readonly oracleSPService:OracleSpService){}
|
|
||||||
|
|
||||||
@Get('/getRegions')
|
|
||||||
getRegions(){
|
|
||||||
return this.oracleSPService.getRegions();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { OracleSpService } from './oraclesp.service';
|
|
||||||
import { OracleSpController } from './oraclesp.controller';
|
|
||||||
import { DbModule } from 'src/db/db.module';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports:[DbModule],
|
|
||||||
providers: [OracleSpService],
|
|
||||||
controllers: [OracleSpController]
|
|
||||||
})
|
|
||||||
export class OracleSpModule {}
|
|
||||||
@ -1,899 +0,0 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
|
||||||
import { DbService } from 'src/db/db.service';
|
|
||||||
import * as oracledb from 'oracledb'
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class OracleSpService {
|
|
||||||
private dbService: DbService;
|
|
||||||
|
|
||||||
constructor(@Inject(DbService) dbService: DbService) {
|
|
||||||
this.dbService = dbService;
|
|
||||||
}
|
|
||||||
|
|
||||||
async getRegions() {
|
|
||||||
let connection;
|
|
||||||
let rows = [];
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
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; // The OUT cursor
|
|
||||||
let rowsBatch;
|
|
||||||
|
|
||||||
do {
|
|
||||||
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
|
||||||
rows = rows.concat(rowsBatch); // Append fetched rows to the main array
|
|
||||||
} while (rowsBatch.length > 0);
|
|
||||||
|
|
||||||
console.log('Rows fetched:', rows);
|
|
||||||
|
|
||||||
// Close the cursor after you're done
|
|
||||||
await cursor.close();
|
|
||||||
} else {
|
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows;
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async InsertRegions() {
|
|
||||||
let connection;
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
sp1(:p_region,:p_name,:p_cursor);
|
|
||||||
END;`, {
|
|
||||||
p_region: {
|
|
||||||
val: "03",
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_name: {
|
|
||||||
val: "",
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_cursor: {
|
|
||||||
type: oracledb.CURSOR,
|
|
||||||
dir: oracledb.BIND_OUT
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let fres = await result.outBinds.p_cursor.getRows();
|
|
||||||
|
|
||||||
return fres
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateRegions() {
|
|
||||||
let connection;
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
sp1(:p_regionID,:p_name,:p_cursor);
|
|
||||||
END;`, {
|
|
||||||
p_regionID: {
|
|
||||||
val: 3,
|
|
||||||
type: oracledb.DB_TYPE_NUMBER
|
|
||||||
},
|
|
||||||
p_name: {
|
|
||||||
val: 'indu1',
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_cursor: {
|
|
||||||
type: oracledb.CURSOR,
|
|
||||||
dir: oracledb.BIND_OUT
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let fres = await result.outBinds.p_cursor.getRows();
|
|
||||||
|
|
||||||
return fres
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async insertNewServiceProider(
|
|
||||||
p_name: String,
|
|
||||||
p_lookupcode: String,
|
|
||||||
p_address1: String,
|
|
||||||
p_address2: String,
|
|
||||||
p_city: String,
|
|
||||||
p_state: String,
|
|
||||||
p_zip: String,
|
|
||||||
p_country: String,
|
|
||||||
p_issuingregion: String,
|
|
||||||
p_replacementregion: String,
|
|
||||||
p_bondsurety: String,
|
|
||||||
p_cargopolicyno: String,
|
|
||||||
p_cargosurety: String,
|
|
||||||
p_user_id: String,
|
|
||||||
) {
|
|
||||||
|
|
||||||
let connection;
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
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_cursor);
|
|
||||||
END;`, {
|
|
||||||
p_name: {
|
|
||||||
val: p_name,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_lookupcode: {
|
|
||||||
val: p_lookupcode,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_address1: {
|
|
||||||
val: p_address1,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_address2: {
|
|
||||||
val: p_address2,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_city: {
|
|
||||||
val: p_city,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_state: {
|
|
||||||
val: p_state,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_zip: {
|
|
||||||
val: p_zip,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_country: {
|
|
||||||
val: p_country,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_issuingregion: {
|
|
||||||
val: p_issuingregion,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_replacementregion: {
|
|
||||||
val: p_replacementregion,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_bondsurety: {
|
|
||||||
val: p_bondsurety,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_cargopolicyno: {
|
|
||||||
val: p_cargopolicyno,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_cargosurety: {
|
|
||||||
val: p_cargosurety,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_user_id: {
|
|
||||||
val: p_user_id,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
|
|
||||||
p_cursor: {
|
|
||||||
type: oracledb.CURSOR,
|
|
||||||
dir: oracledb.BIND_OUT
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let fres = await result.outBinds.res.getRows();
|
|
||||||
|
|
||||||
return fres
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateServiceProider(
|
|
||||||
p_spid: Number,
|
|
||||||
p_name: String,
|
|
||||||
p_lookupcode: String,
|
|
||||||
p_address1: String,
|
|
||||||
p_address2: String,
|
|
||||||
p_city: String,
|
|
||||||
p_state: String,
|
|
||||||
p_zip: String,
|
|
||||||
p_country: String,
|
|
||||||
p_issuingregion: String,
|
|
||||||
p_replacementregion: String,
|
|
||||||
p_bondsurety: String,
|
|
||||||
p_cargopolicyno: String,
|
|
||||||
p_cargosurety: String,
|
|
||||||
p_user_id: String
|
|
||||||
) {
|
|
||||||
|
|
||||||
let connection;
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
USCIB_Managed_Pkg.UpdateSP(
|
|
||||||
:p_spid,
|
|
||||||
:p_name,
|
|
||||||
:p_lookupcode,
|
|
||||||
:p_address1,
|
|
||||||
:p_address2,
|
|
||||||
:p_city,
|
|
||||||
:p_state,
|
|
||||||
:p_zip,
|
|
||||||
:p_country,
|
|
||||||
:p_issuingregion,
|
|
||||||
:p_replacementregion,
|
|
||||||
:p_bondsurety,
|
|
||||||
:p_cargopolicyno,
|
|
||||||
:p_cargosurety,
|
|
||||||
:p_user_id,
|
|
||||||
:p_cursor);
|
|
||||||
END;`, {
|
|
||||||
p_spid: {
|
|
||||||
val: p_spid,
|
|
||||||
type: oracledb.DB_TYPE_NUMBER
|
|
||||||
},
|
|
||||||
p_name: {
|
|
||||||
val: p_name,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_lookupcode: {
|
|
||||||
val: p_lookupcode,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_address1: {
|
|
||||||
val: p_address1,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_address2: {
|
|
||||||
val: p_address2,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_city: {
|
|
||||||
val: p_city,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_state: {
|
|
||||||
val: p_state,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_zip: {
|
|
||||||
val: p_zip,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_country: {
|
|
||||||
val: p_country,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_issuingregion: {
|
|
||||||
val: p_issuingregion,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_replacementregion: {
|
|
||||||
val: p_replacementregion,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_bondsurety: {
|
|
||||||
val: p_bondsurety,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_cargopolicyno: {
|
|
||||||
val: p_cargopolicyno,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_cargosurety: {
|
|
||||||
val: p_cargosurety,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_user_id: {
|
|
||||||
val: p_user_id,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_cursor: {
|
|
||||||
type: oracledb.CURSOR,
|
|
||||||
dir: oracledb.BIND_OUT
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let fres = await result.outBinds.p_cursor.getRows();
|
|
||||||
|
|
||||||
return fres
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async getAllServiceproviders() {
|
|
||||||
|
|
||||||
let connection;
|
|
||||||
let rows = [];
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
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; // The OUT cursor
|
|
||||||
let rowsBatch;
|
|
||||||
|
|
||||||
do {
|
|
||||||
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
|
||||||
rows = rows.concat(rowsBatch); // Append fetched rows to the main array
|
|
||||||
} while (rowsBatch.length > 0);
|
|
||||||
|
|
||||||
console.log('Rows fetched:', rows);
|
|
||||||
|
|
||||||
// Close the cursor after you're done
|
|
||||||
await cursor.close();
|
|
||||||
} else {
|
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows;
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async getSelectedServiceprovider(p_spid: Number) {
|
|
||||||
|
|
||||||
let connection;
|
|
||||||
let rows = [];
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
USCIB_Managed_Pkg.GetSPbySPID(:p_spid,:p_cursor);
|
|
||||||
END;`,
|
|
||||||
{
|
|
||||||
p_spid: {
|
|
||||||
val: 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; // The OUT cursor
|
|
||||||
let rowsBatch;
|
|
||||||
|
|
||||||
do {
|
|
||||||
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
|
||||||
rows = rows.concat(rowsBatch); // Append fetched rows to the main array
|
|
||||||
} while (rowsBatch.length > 0);
|
|
||||||
|
|
||||||
console.log('Rows fetched:', rows);
|
|
||||||
|
|
||||||
// Close the cursor after you're done
|
|
||||||
await cursor.close();
|
|
||||||
} else {
|
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows;
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async insertSPContacts(
|
|
||||||
p_spid: Number,
|
|
||||||
p_firstname: String,
|
|
||||||
p_lastname: String,
|
|
||||||
p_title: String,
|
|
||||||
p_phoneno: String,
|
|
||||||
p_mobileno: String,
|
|
||||||
p_faxno: String,
|
|
||||||
p_emailaddress: String,
|
|
||||||
p_user_id: String
|
|
||||||
) {
|
|
||||||
|
|
||||||
let connection;
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
USCIB_Managed_Pkg.InsertSPContacts(
|
|
||||||
:p_spid,
|
|
||||||
:p_firstname,
|
|
||||||
:p_lastname,
|
|
||||||
:p_title,
|
|
||||||
:p_phoneno,
|
|
||||||
:p_mobileno,
|
|
||||||
:p_faxno,
|
|
||||||
:p_emailaddress,
|
|
||||||
:p_user_id,
|
|
||||||
:p_cursor);
|
|
||||||
END;`, {
|
|
||||||
p_spid: {
|
|
||||||
val: p_spid,
|
|
||||||
type: oracledb.DB_TYPE_NUMBER
|
|
||||||
},
|
|
||||||
p_firstname: {
|
|
||||||
val: p_firstname,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_lastname: {
|
|
||||||
val: p_lastname,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_title: {
|
|
||||||
val: p_title,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_phoneno: {
|
|
||||||
val: p_phoneno,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_mobileno: {
|
|
||||||
val: p_mobileno,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_faxno: {
|
|
||||||
val: p_faxno,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_emailaddress: {
|
|
||||||
val: p_emailaddress,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_user_id: {
|
|
||||||
val: p_user_id,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_cursor: {
|
|
||||||
type: oracledb.CURSOR,
|
|
||||||
dir: oracledb.BIND_OUT
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let fres = await result.outBinds.p_cursor.getRows();
|
|
||||||
|
|
||||||
return fres
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateSPContacts(
|
|
||||||
p_spcontactid: Number,
|
|
||||||
p_firstname: String,
|
|
||||||
p_lastname: String,
|
|
||||||
p_title: String,
|
|
||||||
p_phoneno: String,
|
|
||||||
p_mobileno: String,
|
|
||||||
p_faxno: String,
|
|
||||||
p_emailaddress: String,
|
|
||||||
p_user_id: String,
|
|
||||||
) {
|
|
||||||
|
|
||||||
let connection;
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
USCIB_Managed_Pkg.UpdateSPContacts(
|
|
||||||
:p_spcontactid,
|
|
||||||
:p_firstname,
|
|
||||||
:p_lastname,
|
|
||||||
:p_title,
|
|
||||||
:p_phoneno,
|
|
||||||
:p_mobileno,
|
|
||||||
:p_faxno,
|
|
||||||
:p_emailaddress,
|
|
||||||
:p_user_id,
|
|
||||||
:p_cursor);
|
|
||||||
END;`, {
|
|
||||||
p_spcontactid: {
|
|
||||||
val: p_spcontactid,
|
|
||||||
type: oracledb.DB_TYPE_NUMBER
|
|
||||||
},
|
|
||||||
p_firstname: {
|
|
||||||
val: p_firstname,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_lastname: {
|
|
||||||
val: p_lastname,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_title: {
|
|
||||||
val: p_title,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_phoneno: {
|
|
||||||
val: p_phoneno,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_mobileno: {
|
|
||||||
val: p_mobileno,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_faxno: {
|
|
||||||
val: p_faxno,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_emailaddress: {
|
|
||||||
val: p_emailaddress,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_user_id: {
|
|
||||||
val: p_user_id,
|
|
||||||
type: oracledb.DB_TYPE_VARCHAR
|
|
||||||
},
|
|
||||||
p_cursor: {
|
|
||||||
type: oracledb.CURSOR,
|
|
||||||
dir: oracledb.BIND_OUT
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
||||||
}
|
|
||||||
);
|
|
||||||
let fres = await result.outBinds.p_cursor.getRows();
|
|
||||||
|
|
||||||
return fres
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async getSPcontacts(p_SPid: Number) {
|
|
||||||
let connection;
|
|
||||||
let rows = [];
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
USCIB_Managed_Pkg.GetSPAllContacts( p_SPid,:p_cursor);
|
|
||||||
END;`,
|
|
||||||
{
|
|
||||||
p_SPid: {
|
|
||||||
val: 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; // The OUT cursor
|
|
||||||
let rowsBatch;
|
|
||||||
|
|
||||||
do {
|
|
||||||
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
|
||||||
rows = rows.concat(rowsBatch); // Append fetched rows to the main array
|
|
||||||
} while (rowsBatch.length > 0);
|
|
||||||
|
|
||||||
console.log('Rows fetched:', rows);
|
|
||||||
|
|
||||||
// Close the cursor after you're done
|
|
||||||
await cursor.close();
|
|
||||||
} else {
|
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows;
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async setSPDefaultcontact(p_spcontactid: Number) {
|
|
||||||
let connection;
|
|
||||||
let rows = [];
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
USCIB_Managed_Pkg.SetDefaultContact(:p_spcontactid);
|
|
||||||
END;`,
|
|
||||||
{
|
|
||||||
p_cursor: {
|
|
||||||
val: p_spcontactid,
|
|
||||||
type: oracledb.DB_TYPE_NUMBER,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// {
|
|
||||||
// outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
||||||
// }
|
|
||||||
);
|
|
||||||
|
|
||||||
// if (result.outBinds && result.outBinds.p_cursor) {
|
|
||||||
// const cursor = result.outBinds.p_cursor; // The OUT cursor
|
|
||||||
// let rowsBatch;
|
|
||||||
|
|
||||||
// do {
|
|
||||||
// rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
|
||||||
// rows = rows.concat(rowsBatch); // Append fetched rows to the main array
|
|
||||||
// } while (rowsBatch.length > 0);
|
|
||||||
|
|
||||||
// console.log('Rows fetched:', rows);
|
|
||||||
|
|
||||||
// // Close the cursor after you're done
|
|
||||||
// await cursor.close();
|
|
||||||
// } else {
|
|
||||||
// throw new Error('No cursor returned from the stored procedure');
|
|
||||||
// }
|
|
||||||
|
|
||||||
return 'rows';
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async inactivateSPContact(p_spcontactid: Number) {
|
|
||||||
let connection;
|
|
||||||
let rows = [];
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
USCIB_Managed_Pkg.InActivateSPContacts(:p_spcontactid);
|
|
||||||
END;`,
|
|
||||||
{
|
|
||||||
p_cursor: {
|
|
||||||
val: p_spcontactid,
|
|
||||||
type: oracledb.DB_TYPE_NUMBER,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// {
|
|
||||||
// outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
||||||
// }
|
|
||||||
);
|
|
||||||
|
|
||||||
// if (result.outBinds && result.outBinds.p_cursor) {
|
|
||||||
// const cursor = result.outBinds.p_cursor; // The OUT cursor
|
|
||||||
// let rowsBatch;
|
|
||||||
|
|
||||||
// do {
|
|
||||||
// rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
|
||||||
// rows = rows.concat(rowsBatch); // Append fetched rows to the main array
|
|
||||||
// } while (rowsBatch.length > 0);
|
|
||||||
|
|
||||||
// console.log('Rows fetched:', rows);
|
|
||||||
|
|
||||||
// // Close the cursor after you're done
|
|
||||||
// await cursor.close();
|
|
||||||
// } else {
|
|
||||||
// throw new Error('No cursor returned from the stored procedure');
|
|
||||||
// }
|
|
||||||
|
|
||||||
return 'rows';
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async getSPDefaultcontact(p_SPid: Number) {
|
|
||||||
|
|
||||||
let connection;
|
|
||||||
let rows = [];
|
|
||||||
try {
|
|
||||||
// Connect to the Oracle database using oracledb
|
|
||||||
connection = await this.dbService.getDataSource()
|
|
||||||
if (!connection) {
|
|
||||||
throw new Error('No DB Connected')
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await connection.execute(
|
|
||||||
`BEGIN
|
|
||||||
USCIB_Managed_Pkg.GetSPDefaultContacts( p_SPid,:p_cursor);
|
|
||||||
END;`,
|
|
||||||
{
|
|
||||||
p_SPid: {
|
|
||||||
val: 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; // The OUT cursor
|
|
||||||
let rowsBatch;
|
|
||||||
|
|
||||||
do {
|
|
||||||
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
|
||||||
rows = rows.concat(rowsBatch); // Append fetched rows to the main array
|
|
||||||
} while (rowsBatch.length > 0);
|
|
||||||
|
|
||||||
console.log('Rows fetched:', rows);
|
|
||||||
|
|
||||||
// Close the cursor after you're done
|
|
||||||
await cursor.close();
|
|
||||||
} else {
|
|
||||||
throw new Error('No cursor returned from the stored procedure');
|
|
||||||
}
|
|
||||||
|
|
||||||
return rows;
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error fetching users: ', err);
|
|
||||||
throw new Error('Error fetching users');
|
|
||||||
} finally {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user