updated service provider api
This commit is contained in:
parent
675c086afe
commit
cf86f29ed9
80
api.http
80
api.http
@ -34,6 +34,12 @@ GET http://localhost:3000/oracle/GetAllServiceproviders
|
||||
|
||||
###
|
||||
|
||||
//GetSelectedServiceprovider
|
||||
|
||||
GET http://localhost:3000/oracle/GetSelectedServiceprovider
|
||||
|
||||
###
|
||||
|
||||
//InsertNewServiceProvider
|
||||
|
||||
POST http://localhost:3000/oracle/InsertNewServiceProvider
|
||||
@ -58,6 +64,78 @@ Content-Type: application/json
|
||||
|
||||
###
|
||||
|
||||
//
|
||||
//UpdateServiceProvider
|
||||
|
||||
PUT http://localhost:3000/oracle/UpdateServiceProvider
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"p_spid": 1,
|
||||
"p_name": "Service Provider Name",
|
||||
"p_lookupcode": "SP001",
|
||||
"p_address1": "123 Main St",
|
||||
"p_address2": "Suite 100",
|
||||
"p_city": "Anytown",
|
||||
"p_state": "CA",
|
||||
"p_zip": "90210",
|
||||
"p_country": "USA",
|
||||
"p_issuingregion": "Region A",
|
||||
"p_replacementregion": "Region B",
|
||||
"p_bondsurety": "Surety Co.",
|
||||
"p_cargopolicyno": "CP123456",
|
||||
"p_cargosurety": "Cargo Surety Co.",
|
||||
"p_user_id": "user123"
|
||||
}
|
||||
|
||||
|
||||
//GetSPcontacts
|
||||
|
||||
GET http://localhost:3000/oracle/GetSPcontacts
|
||||
|
||||
###
|
||||
|
||||
//GetSPDefaultcontact
|
||||
|
||||
###
|
||||
|
||||
//InsertSPContacts
|
||||
|
||||
POST http://localhost:3000/oracle/InsertSPContacts
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"p_name": "Service Provider Name",
|
||||
"p_lookupcode": "SP001",
|
||||
"p_address1": "123 Main St",
|
||||
"p_address2": "Suite 100",
|
||||
"p_city": "Anytown",
|
||||
"p_state": "CA",
|
||||
"p_zip": "90210",
|
||||
"p_country": "USA",
|
||||
"p_issuingregion": "Region A",
|
||||
"p_replacementregion": "Region B",
|
||||
"p_bondsurety": "Surety Co.",
|
||||
"p_cargopolicyno": "CP123456",
|
||||
"p_cargosurety": "Cargo Surety Co.",
|
||||
"p_user_id": "user123"
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
//UpdateSPContacts
|
||||
|
||||
|
||||
###
|
||||
|
||||
//SetSPDefaultcontact
|
||||
|
||||
|
||||
###
|
||||
|
||||
//InactivateSPContact
|
||||
|
||||
|
||||
|
||||
###
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Body, Controller, Get, Patch, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Patch, Post, Put } from '@nestjs/common';
|
||||
import { OracleService } from './oracle.service';
|
||||
import { InsertNewServiceProviderDTO, InsertRegionsDto, UpdateRegionDto } from './oracle.dto';
|
||||
import { GetSelectedServiceProviderDTO, GetSPcontactsDTO, InsertNewServiceProviderDTO, InsertRegionsDto, InsertSPContactsDTO, UpdateRegionDto, UpdateServiceProviderDTO } from './oracle.dto';
|
||||
|
||||
@Controller('oracle')
|
||||
export class OracleController {
|
||||
@ -26,9 +26,14 @@ export class OracleController {
|
||||
return this.oarcleService.getAllServiceproviders();
|
||||
}
|
||||
|
||||
@Get('/GetSelectedServiceprovider')
|
||||
getSelectedServiceprovider(@Body() body: GetSelectedServiceProviderDTO) {
|
||||
return this.oarcleService.getSelectedServiceprovider(body.p_spid);
|
||||
}
|
||||
|
||||
@Post('/InsertNewServiceProvider')
|
||||
insertNewServiceProvider(@Body() body: InsertNewServiceProviderDTO) {
|
||||
return this.oarcleService.insertNewServiceProider(
|
||||
return this.oarcleService.insertNewServiceProvider(
|
||||
body.p_name,
|
||||
body.p_lookupcode,
|
||||
body.p_address1,
|
||||
@ -45,4 +50,45 @@ export class OracleController {
|
||||
body.p_user_id
|
||||
)
|
||||
}
|
||||
|
||||
@Put('/UpdateServiceProvider')
|
||||
updateServiceProider(@Body() body: UpdateServiceProviderDTO) {
|
||||
return this.oarcleService.updateServiceProvider(
|
||||
body.p_spid,
|
||||
body.p_name,
|
||||
body.p_lookupcode,
|
||||
body.p_address1,
|
||||
body.p_address2,
|
||||
body.p_city,
|
||||
body.p_state,
|
||||
body.p_zip,
|
||||
body.p_country,
|
||||
body.p_issuingregion,
|
||||
body.p_replacementregion,
|
||||
body.p_bondsurety,
|
||||
body.p_cargopolicyno,
|
||||
body.p_cargosurety,
|
||||
body.p_user_id
|
||||
)
|
||||
}
|
||||
|
||||
@Get('/GetSPcontacts')
|
||||
getSPcontacts(@Body() body: GetSPcontactsDTO) {
|
||||
return this.oarcleService.getSPcontacts(body.p_SPid);
|
||||
}
|
||||
|
||||
@Post('InsertSPContacts')
|
||||
insertSPContacts(@Body() body: InsertSPContactsDTO){
|
||||
return this.oarcleService.insertSPContacts(
|
||||
body.p_spid,
|
||||
body.p_firstname,
|
||||
body.p_lastname,
|
||||
body.p_title,
|
||||
body.p_phoneno,
|
||||
body.p_mobileno,
|
||||
body.p_faxno,
|
||||
body.p_emailaddress,
|
||||
body.p_user_id
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { IsNumber, IsOptional, IsString } from 'class-validator';
|
||||
import { IsEmail, IsNumber, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
export class InsertRegionsDto {
|
||||
@IsString()
|
||||
@ -16,6 +16,11 @@ export class UpdateRegionDto {
|
||||
p_name: string;
|
||||
}
|
||||
|
||||
export class GetSelectedServiceProviderDTO {
|
||||
@IsNumber()
|
||||
p_spid: number;
|
||||
}
|
||||
|
||||
export class InsertNewServiceProviderDTO {
|
||||
@IsString()
|
||||
p_name: string;
|
||||
@ -60,3 +65,84 @@ export class InsertNewServiceProviderDTO {
|
||||
p_user_id: string;
|
||||
}
|
||||
|
||||
export class UpdateServiceProviderDTO {
|
||||
@IsNumber()
|
||||
p_spid: number;
|
||||
|
||||
@IsString()
|
||||
p_name: string;
|
||||
|
||||
@IsString()
|
||||
p_lookupcode: string;
|
||||
|
||||
@IsString()
|
||||
p_address1: string;
|
||||
|
||||
@IsString()
|
||||
p_address2: string;
|
||||
|
||||
@IsString()
|
||||
p_city: string;
|
||||
|
||||
@IsString()
|
||||
p_state: string;
|
||||
|
||||
@IsString()
|
||||
p_zip: string;
|
||||
|
||||
@IsString()
|
||||
p_country: string;
|
||||
|
||||
@IsString()
|
||||
p_issuingregion: string;
|
||||
|
||||
@IsString()
|
||||
p_replacementregion: string;
|
||||
|
||||
@IsString()
|
||||
p_bondsurety: string;
|
||||
|
||||
@IsString()
|
||||
p_cargopolicyno: string;
|
||||
|
||||
@IsString()
|
||||
p_cargosurety: string;
|
||||
|
||||
@IsString()
|
||||
p_user_id: string;
|
||||
}
|
||||
|
||||
export class GetSPcontactsDTO {
|
||||
@IsNumber()
|
||||
p_SPid: number;
|
||||
}
|
||||
|
||||
export class InsertSPContactsDTO {
|
||||
@IsNumber()
|
||||
p_spid: number;
|
||||
|
||||
@IsString()
|
||||
p_firstname: string;
|
||||
|
||||
@IsString()
|
||||
p_lastname: string;
|
||||
|
||||
@IsString()
|
||||
p_title: string;
|
||||
|
||||
@IsString()
|
||||
p_phoneno: string;
|
||||
|
||||
@IsString()
|
||||
p_mobileno: string;
|
||||
|
||||
@IsString()
|
||||
p_faxno: string;
|
||||
|
||||
@IsEmail()
|
||||
p_emailaddress: string;
|
||||
|
||||
@IsString()
|
||||
p_user_id: string;
|
||||
}
|
||||
|
||||
|
||||
@ -142,7 +142,7 @@ export class OracleService {
|
||||
}
|
||||
}
|
||||
|
||||
async insertNewServiceProider(
|
||||
async insertNewServiceProvider(
|
||||
p_name: String,
|
||||
p_lookupcode: String,
|
||||
p_address1: String,
|
||||
@ -263,7 +263,7 @@ export class OracleService {
|
||||
|
||||
}
|
||||
|
||||
async updateServiceProider(
|
||||
async updateServiceProvider(
|
||||
p_spid: Number,
|
||||
p_name: String,
|
||||
p_lookupcode: String,
|
||||
@ -498,4 +498,147 @@ 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 {
|
||||
}
|
||||
}
|
||||
|
||||
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.oracleDBService.getConnection()
|
||||
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 {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user