updated uscib apis

This commit is contained in:
Kallesh B S 2025-02-28 11:06:07 +05:30
parent 2012144f62
commit fbf3de8cdc
4 changed files with 444 additions and 251 deletions

View File

@ -1,9 +1,3 @@
// GetRegions
GET http://localhost:3000/oracle/GetRegions
###
// InsertRegions
POST http://localhost:3000/oracle/InsertRegions
@ -28,17 +22,12 @@ Content-Type: application/json
###
// GetAllServiceproviders
// GetRegions
GET http://localhost:3000/oracle/GetAllServiceproviders
GET http://localhost:3000/oracle/GetRegions
###
//GetSelectedServiceprovider
GET http://localhost:3000/oracle/GetSelectedServiceprovider/12
###
//InsertNewServiceProvider
@ -64,6 +53,7 @@ Content-Type: application/json
###
//UpdateServiceProvider
PUT http://localhost:3000/oracle/UpdateServiceProvider
@ -89,15 +79,15 @@ Content-Type: application/json
###
//GetSPcontacts
// GetAllServiceproviders
GET http://localhost:3000/oracle/GetSPcontacts/12
GET http://localhost:3000/oracle/GetAllServiceproviders
###
//GetSPDefaultcontact
//GetSelectedServiceprovider
GET http://localhost:3000/oracle/GetSPDefaultcontact/12
GET http://localhost:3000/oracle/GetSelectedServiceprovider/12
###
@ -120,6 +110,12 @@ Content-Type: application/json
###
//SetSPDefaultcontact
POST http://localhost:3000/oracle/SetSPDefaultcontact/12
###
//UpdateSPContacts
PUT http://localhost:3000/oracle/UpdateSPContacts
@ -139,9 +135,9 @@ Content-Type: application/json
###
//SetSPDefaultcontact
//GetSPcontacts
POST http://localhost:3000/oracle/SetSPDefaultcontact/12
GET http://localhost:3000/oracle/GetSPcontacts/12
###
@ -151,4 +147,39 @@ POST http://localhost:3000/oracle/InactivateSPContact/12
###
//GetSPDefaultcontact
GET http://localhost:3000/oracle/GetSPDefaultcontact/12
###
//GetAllSPcontacts
GET http://localhost:3000/oracle/GetAllSPcontacts
###
//CreateCarnetSequence
POST http://localhost:3000/oracle/CreateCarnetSequence
Content-Type: application/json
{}
###
//GetCarnetSequence
GET http://localhost:3000/oracle/GetCarnetSequence/12
###

View File

@ -1,15 +1,12 @@
import { Body, Controller, Get, Param, ParseIntPipe, Patch, Post, Put } from '@nestjs/common';
import { OracleService } from './oracle.service';
import { GetSelectedServiceProviderDTO, GetSPcontactsDTO, InsertNewServiceProviderDTO, InsertRegionsDto, InsertSPContactsDTO, UpdateRegionDto, UpdateServiceProviderDTO, UpdateSPContactsDTO } from './oracle.dto';
import { CreateCarnetSequenceDTO, InsertNewServiceProviderDTO, InsertRegionsDto, InsertSPContactsDTO, UpdateRegionDto, UpdateServiceProviderDTO, UpdateSPContactsDTO } from './oracle.dto';
@Controller('oracle')
export class OracleController {
constructor(private readonly oarcleService: OracleService) { }
@Get('/GetRegions')
getRegions() {
return this.oarcleService.getRegions();
}
// Regions
@Post('/InsertRegions')
insertRegions(@Body() body: InsertRegionsDto) {
@ -21,15 +18,12 @@ export class OracleController {
return this.oarcleService.updateRegions(body.p_regionID, body.p_name);
}
@Get('GetAllServiceproviders')
getAllServiceproviders() {
return this.oarcleService.getAllServiceproviders();
@Get('/GetRegions')
getRegions() {
return this.oarcleService.getRegions();
}
@Get('/GetSelectedServiceprovider/:id')
getSelectedServiceprovider(@Param('id', ParseIntPipe) id:number) {
return this.oarcleService.getSelectedServiceprovider(id);
}
// Service Provider [ SP ]
@Post('/InsertNewServiceProvider')
insertNewServiceProvider(@Body() body: InsertNewServiceProviderDTO) {
@ -72,20 +66,24 @@ export class OracleController {
)
}
@Get('/GetSPcontacts/:id')
getSPcontacts(@Param('id', ParseIntPipe) id:number) {
return this.oarcleService.getSPcontacts(id);
@Get('GetAllServiceproviders')
getAllServiceproviders() {
return this.oarcleService.getAllServiceproviders();
}
@Get('/GetSPDefaultcontact/:id')
getSPDefaultcontact(@Param('id', ParseIntPipe) id:number){
return this.oarcleService.getSPDefaultcontact(id)
@Get('/GetSelectedServiceprovider/:id')
getSelectedServiceprovider(@Param('id', ParseIntPipe) id:number) {
return this.oarcleService.getServiceproviderByID(id);
}
// SPContacts
@Post('/InsertSPContacts')
insertSPContacts(@Body() body: InsertSPContactsDTO){
return this.oarcleService.insertSPContacts(
body.p_spid,
body.p_defcontactflag,
body.p_firstname,
body.p_lastname,
body.p_title,
@ -97,6 +95,11 @@ export class OracleController {
)
}
@Post('/SetSPDefaultcontact/:id')
setSPDefaultcontact(@Param('id', ParseIntPipe) id:number){
return this.oarcleService.setSPDefaultcontact(id)
}
@Put('/UpdateSPContacts')
updateSPContacts(@Body() body: UpdateSPContactsDTO){
return this.oarcleService.updateSPContacts(
@ -112,15 +115,36 @@ export class OracleController {
)
}
@Post('/SetSPDefaultcontact/:id')
setSPDefaultcontact(@Param('id', ParseIntPipe) id:number){
return this.oarcleService.setSPDefaultcontact(id)
}
@Post('/InactivateSPContact/:id')
inactivateSPContact(@Param('id', ParseIntPipe) id:number){
return this.oarcleService.inactivateSPContact(id)
}
@Get('/GetSPDefaultcontact/:id')
getSPDefaultcontact(@Param('id', ParseIntPipe) id:number){
return this.oarcleService.getSPDefaultcontacts(id)
}
@Get('/GetAllSPcontacts')
getSPcontacts() {
return this.oarcleService.getSPcontacts();
}
// Carnet Sequence
@Post('/CreateCarnetSequence/')
createCarnetSequence(@Body() body:CreateCarnetSequenceDTO){
return this.oarcleService.createCarnetSequence(
body.p_spid,
body.p_regionid,
body.p_startnumber,
body.p_endnumber,
body.p_carnettype
)
}
@Get('/GetCarnetSequence/:id')
getCarnetSequence(@Param('id', ParseIntPipe) id:number){
return this.oarcleService.getCarnetSequence(id)
}
}

View File

@ -1,4 +1,4 @@
import { IsEmail, IsNumber, IsOptional, IsString } from 'class-validator';
import { IsEmail, IsNumber, IsString } from 'class-validator';
export class InsertRegionsDto {
@IsString()
@ -16,10 +16,10 @@ export class UpdateRegionDto {
p_name: string;
}
export class GetSelectedServiceProviderDTO {
@IsNumber()
p_spid: number;
}
// export class GetSelectedServiceProviderDTO {
// @IsNumber()
// p_spid: number;
// }
export class InsertNewServiceProviderDTO {
@IsString()
@ -112,15 +112,18 @@ export class UpdateServiceProviderDTO {
p_user_id: string;
}
export class GetSPcontactsDTO {
@IsNumber()
p_SPid: number;
}
// export class GetSPcontactsDTO {
// @IsNumber()
// p_SPid: number;
// }
export class InsertSPContactsDTO {
@IsNumber()
p_spid: number;
@IsString()
p_defcontactflag: string;
@IsString()
p_firstname: string;
@ -146,7 +149,6 @@ export class InsertSPContactsDTO {
p_user_id: string;
}
export class UpdateSPContactsDTO {
@IsNumber()
p_spcontactid: number;
@ -175,3 +177,16 @@ export class UpdateSPContactsDTO {
@IsString()
p_user_id: string;
}
export class CreateCarnetSequenceDTO {
@IsNumber()
p_spid: number;
@IsNumber()
p_regionid: number;
@IsNumber()
p_startnumber: number;
@IsNumber()
p_endnumber: number;
@IsString()
p_carnettype: string
}

View File

@ -6,54 +6,7 @@ import * as oracledb from 'oracledb'
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 { }
}
// Regions API
async insertRegions(p_region: String, p_name: String) {
let connection;
@ -139,6 +92,57 @@ export class OracleService {
} finally { }
}
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 { }
}
// Servipe provider [ SP ]
async insertNewServiceProvider(
p_name: String,
p_lookupcode: String,
@ -434,7 +438,7 @@ export class OracleService {
}
async getSelectedServiceprovider(p_spid: Number) {
async getServiceproviderByID(p_spid: Number) {
let connection;
let rows = [];
@ -490,62 +494,11 @@ export class OracleService {
}
async getSPcontacts(p_SPid: number) {
let connection;
let rows = [];
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
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 { }
}
// Service provider contacts [ SPContacts ]
async insertSPContacts(
p_spid: number,
p_defcontactflag: string,
p_firstname: string,
p_lastname: string,
p_title: string,
@ -567,6 +520,7 @@ export class OracleService {
`BEGIN
USCIB_Managed_Pkg.InsertSPContacts(
:p_spid,
:p_defcontactflag,
:p_firstname,
:p_lastname,
:p_title,
@ -581,6 +535,10 @@ export class OracleService {
val: p_spid,
type: oracledb.DB_TYPE_NUMBER
},
p_defcontactflag: {
val: p_defcontactflag,
type: oracledb.DB_TYPE_VARCHAR
},
p_firstname: {
val: p_firstname,
type: oracledb.DB_TYPE_VARCHAR
@ -631,6 +589,39 @@ export class OracleService {
} finally { }
}
async setSPDefaultcontact(p_spcontactid: number) {
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
USCIB_Managed_Pkg.SetDefaultContact(:p_spcontactid);
END;`,
{
p_spcontactid: {
val: p_spcontactid,
type: oracledb.DB_TYPE_NUMBER
},
}
);
await connection.commit();
return "SP executed successfully"
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
async updateSPContacts(
p_spcontactid: number,
p_firstname: string,
@ -718,7 +709,39 @@ export class OracleService {
} finally { }
}
async getSPDefaultcontact(p_SPid: number) {
async inactivateSPContact(p_spcontactid: number) {
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
USCIB_Managed_Pkg.InActivateSPContacts(:p_spcontactid);
END;`, {
p_spcontactid: {
val: p_spcontactid,
type: oracledb.DB_TYPE_NUMBER
}
}
);
await connection.commit();
return "SP executed successfully"
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
async getSPDefaultcontacts(p_SPid: number) {
let connection;
let rows = [];
@ -757,8 +780,6 @@ export class OracleService {
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 {
@ -774,9 +795,9 @@ export class OracleService {
}
async setSPDefaultcontact(p_spcontactid: number) {
async getSPcontacts() {
let connection;
let rows = [];
try {
// Connect to the Oracle database using oracledb
connection = await this.oracleDBService.getConnection()
@ -786,29 +807,53 @@ export class OracleService {
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.SetDefaultContact(:p_spcontactid);
USCIB_Managed_Pkg.GetSPAllContacts(:p_cursor);
END;`,
{
p_spcontactid: {
val: p_spcontactid,
type: oracledb.DB_TYPE_NUMBER
p_cursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
}
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
await connection.commit();
if (result.outBinds && result.outBinds.p_cursor) {
const cursor = result.outBinds.p_cursor; // The OUT cursor
let rowsBatch;
return "SP executed successfully"
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) {
// CarnetSequence
async createCarnetSequence(
p_spid: number,
p_regionid: number,
p_startnumber: number,
p_endnumber: number,
p_carnettype: string
) {
let connection;
try {
// Connect to the Oracle database using oracledb
@ -819,23 +864,101 @@ export class OracleService {
const result = await connection.execute(
`BEGIN
USCIB_Managed_Pkg.InActivateSPContacts(:p_spcontactid);
USCIB_Managed_Pkg.CreateCarnetSequence(
:p_spid,
:p_regionid,
:p_startnumber,
:p_endnumber,
:p_carnettype,
:p_cursor);
END;`, {
p_spcontactid: {
val: p_spcontactid,
p_spid: {
val: p_spid,
type: oracledb.DB_TYPE_NUMBER
},
p_regionid: {
val: p_regionid,
type: oracledb.DB_TYPE_NUMBER
},
p_startnumber: {
val: p_startnumber,
type: oracledb.DB_TYPE_NUMBER
},
p_endnumber: {
val: p_endnumber,
type: oracledb.DB_TYPE_NUMBER
},
p_carnettype: {
val: p_carnettype,
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();
await connection.commit();
return "SP executed successfully"
return fres
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
async getCarnetSequence(p_spid: number) {
let connection;
let rows = [];
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
USCIB_Managed_Pkg.GetCarnetSequence(: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);
// 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 { }
}
}