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 // InsertRegions
POST http://localhost:3000/oracle/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 //InsertNewServiceProvider
@ -64,6 +53,7 @@ Content-Type: application/json
### ###
//UpdateServiceProvider //UpdateServiceProvider
PUT http://localhost:3000/oracle/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 //UpdateSPContacts
PUT http://localhost:3000/oracle/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 { Body, Controller, Get, Param, ParseIntPipe, Patch, Post, Put } from '@nestjs/common';
import { OracleService } from './oracle.service'; 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') @Controller('oracle')
export class OracleController { export class OracleController {
constructor(private readonly oarcleService: OracleService) { } constructor(private readonly oarcleService: OracleService) { }
@Get('/GetRegions') // Regions
getRegions() {
return this.oarcleService.getRegions();
}
@Post('/InsertRegions') @Post('/InsertRegions')
insertRegions(@Body() body: InsertRegionsDto) { insertRegions(@Body() body: InsertRegionsDto) {
@ -21,15 +18,12 @@ export class OracleController {
return this.oarcleService.updateRegions(body.p_regionID, body.p_name); return this.oarcleService.updateRegions(body.p_regionID, body.p_name);
} }
@Get('GetAllServiceproviders') @Get('/GetRegions')
getAllServiceproviders() { getRegions() {
return this.oarcleService.getAllServiceproviders(); return this.oarcleService.getRegions();
} }
@Get('/GetSelectedServiceprovider/:id') // Service Provider [ SP ]
getSelectedServiceprovider(@Param('id', ParseIntPipe) id:number) {
return this.oarcleService.getSelectedServiceprovider(id);
}
@Post('/InsertNewServiceProvider') @Post('/InsertNewServiceProvider')
insertNewServiceProvider(@Body() body: InsertNewServiceProviderDTO) { insertNewServiceProvider(@Body() body: InsertNewServiceProviderDTO) {
@ -72,20 +66,24 @@ export class OracleController {
) )
} }
@Get('/GetSPcontacts/:id') @Get('GetAllServiceproviders')
getSPcontacts(@Param('id', ParseIntPipe) id:number) { getAllServiceproviders() {
return this.oarcleService.getSPcontacts(id); return this.oarcleService.getAllServiceproviders();
} }
@Get('/GetSPDefaultcontact/:id') @Get('/GetSelectedServiceprovider/:id')
getSPDefaultcontact(@Param('id', ParseIntPipe) id:number){ getSelectedServiceprovider(@Param('id', ParseIntPipe) id:number) {
return this.oarcleService.getSPDefaultcontact(id) return this.oarcleService.getServiceproviderByID(id);
} }
// SPContacts
@Post('/InsertSPContacts') @Post('/InsertSPContacts')
insertSPContacts(@Body() body: InsertSPContactsDTO){ insertSPContacts(@Body() body: InsertSPContactsDTO){
return this.oarcleService.insertSPContacts( return this.oarcleService.insertSPContacts(
body.p_spid, body.p_spid,
body.p_defcontactflag,
body.p_firstname, body.p_firstname,
body.p_lastname, body.p_lastname,
body.p_title, 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') @Put('/UpdateSPContacts')
updateSPContacts(@Body() body: UpdateSPContactsDTO){ updateSPContacts(@Body() body: UpdateSPContactsDTO){
return this.oarcleService.updateSPContacts( 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') @Post('/InactivateSPContact/:id')
inactivateSPContact(@Param('id', ParseIntPipe) id:number){ inactivateSPContact(@Param('id', ParseIntPipe) id:number){
return this.oarcleService.inactivateSPContact(id) 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 { export class InsertRegionsDto {
@IsString() @IsString()
@ -16,10 +16,10 @@ export class UpdateRegionDto {
p_name: string; p_name: string;
} }
export class GetSelectedServiceProviderDTO { // export class GetSelectedServiceProviderDTO {
@IsNumber() // @IsNumber()
p_spid: number; // p_spid: number;
} // }
export class InsertNewServiceProviderDTO { export class InsertNewServiceProviderDTO {
@IsString() @IsString()
@ -112,15 +112,18 @@ export class UpdateServiceProviderDTO {
p_user_id: string; p_user_id: string;
} }
export class GetSPcontactsDTO { // export class GetSPcontactsDTO {
@IsNumber() // @IsNumber()
p_SPid: number; // p_SPid: number;
} // }
export class InsertSPContactsDTO { export class InsertSPContactsDTO {
@IsNumber() @IsNumber()
p_spid: number; p_spid: number;
@IsString()
p_defcontactflag: string;
@IsString() @IsString()
p_firstname: string; p_firstname: string;
@ -146,7 +149,6 @@ export class InsertSPContactsDTO {
p_user_id: string; p_user_id: string;
} }
export class UpdateSPContactsDTO { export class UpdateSPContactsDTO {
@IsNumber() @IsNumber()
p_spcontactid: number; p_spcontactid: number;
@ -175,3 +177,16 @@ export class UpdateSPContactsDTO {
@IsString() @IsString()
p_user_id: string; 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 { export class OracleService {
constructor(private readonly oracleDBService: OracleDBService) { } constructor(private readonly oracleDBService: OracleDBService) { }
async getRegions() { // Regions API
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) { async insertRegions(p_region: String, p_name: String) {
let connection; let connection;
@ -139,6 +92,57 @@ export class OracleService {
} finally { } } 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( async insertNewServiceProvider(
p_name: String, p_name: String,
p_lookupcode: String, p_lookupcode: String,
@ -434,7 +438,7 @@ export class OracleService {
} }
async getSelectedServiceprovider(p_spid: Number) { async getServiceproviderByID(p_spid: Number) {
let connection; let connection;
let rows = []; let rows = [];
@ -490,62 +494,11 @@ export class OracleService {
} }
async getSPcontacts(p_SPid: number) { // Service provider contacts [ SPContacts ]
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 { }
}
async insertSPContacts( async insertSPContacts(
p_spid: number, p_spid: number,
p_defcontactflag: string,
p_firstname: string, p_firstname: string,
p_lastname: string, p_lastname: string,
p_title: string, p_title: string,
@ -567,6 +520,7 @@ export class OracleService {
`BEGIN `BEGIN
USCIB_Managed_Pkg.InsertSPContacts( USCIB_Managed_Pkg.InsertSPContacts(
:p_spid, :p_spid,
:p_defcontactflag,
:p_firstname, :p_firstname,
:p_lastname, :p_lastname,
:p_title, :p_title,
@ -581,6 +535,10 @@ export class OracleService {
val: p_spid, val: p_spid,
type: oracledb.DB_TYPE_NUMBER type: oracledb.DB_TYPE_NUMBER
}, },
p_defcontactflag: {
val: p_defcontactflag,
type: oracledb.DB_TYPE_VARCHAR
},
p_firstname: { p_firstname: {
val: p_firstname, val: p_firstname,
type: oracledb.DB_TYPE_VARCHAR type: oracledb.DB_TYPE_VARCHAR
@ -631,6 +589,39 @@ export class OracleService {
} finally { } } 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( async updateSPContacts(
p_spcontactid: number, p_spcontactid: number,
p_firstname: string, p_firstname: string,
@ -718,7 +709,39 @@ export class OracleService {
} finally { } } 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 connection;
let rows = []; let rows = [];
@ -757,8 +780,6 @@ export class OracleService {
rows = rows.concat(rowsBatch); // Append fetched rows to the main array rows = rows.concat(rowsBatch); // Append fetched rows to the main array
} while (rowsBatch.length > 0); } while (rowsBatch.length > 0);
console.log('Rows fetched:', rows);
// Close the cursor after you're done // Close the cursor after you're done
await cursor.close(); await cursor.close();
} else { } else {
@ -774,9 +795,9 @@ export class OracleService {
} }
async setSPDefaultcontact(p_spcontactid: number) { async getSPcontacts() {
let connection; let connection;
let rows = [];
try { try {
// Connect to the Oracle database using oracledb // Connect to the Oracle database using oracledb
connection = await this.oracleDBService.getConnection() connection = await this.oracleDBService.getConnection()
@ -786,29 +807,53 @@ export class OracleService {
const result = await connection.execute( const result = await connection.execute(
`BEGIN `BEGIN
USCIB_Managed_Pkg.SetDefaultContact(:p_spcontactid); USCIB_Managed_Pkg.GetSPAllContacts(:p_cursor);
END;`, END;`,
{ {
p_spcontactid: { p_cursor: {
val: p_spcontactid, type: oracledb.CURSOR,
type: oracledb.DB_TYPE_NUMBER 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) { } catch (err) {
console.error('Error fetching users: ', err); console.error('Error fetching users: ', err);
throw new Error('Error fetching users'); throw new Error('Error fetching users');
} finally { } } 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; let connection;
try { try {
// Connect to the Oracle database using oracledb // Connect to the Oracle database using oracledb
@ -819,23 +864,101 @@ export class OracleService {
const result = await connection.execute( const result = await connection.execute(
`BEGIN `BEGIN
USCIB_Managed_Pkg.InActivateSPContacts(:p_spcontactid); USCIB_Managed_Pkg.CreateCarnetSequence(
:p_spid,
:p_regionid,
:p_startnumber,
:p_endnumber,
:p_carnettype,
:p_cursor);
END;`, { END;`, {
p_spcontactid: { p_spid: {
val: p_spcontactid, val: p_spid,
type: oracledb.DB_TYPE_NUMBER 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 fres
return "SP executed successfully"
} catch (err) { } catch (err) {
console.error('Error fetching users: ', err); console.error('Error fetching users: ', err);
throw new Error('Error fetching users'); throw new Error('Error fetching users');
} finally { } } 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 { }
} }
} }