BE/src/oracle/uscib-managed-sp/sp/sp.service.ts

353 lines
11 KiB
TypeScript
Raw Normal View History

2025-03-25 17:10:33 +05:30
import { Injectable } from '@nestjs/common';
import { OracleDBService } from 'src/db/db.service';
import * as oracledb from 'oracledb'
2025-04-02 13:03:48 +05:30
import { getSelectedServiceproviderDTO, InsertNewServiceProviderDTO, UpdateServiceProviderDTO } from './sp.dto';
2025-03-25 17:10:33 +05:30
@Injectable()
export class SpService {
constructor(private readonly oracleDBService: OracleDBService) { }
2025-04-02 13:03:48 +05:30
async insertNewServiceProvider(body: InsertNewServiceProviderDTO) {
2025-03-25 17:10:33 +05:30
let connection;
try {
2025-04-02 13:03:48 +05:30
2025-03-25 17:10:33 +05:30
connection = await this.oracleDBService.getConnection()
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_NOTES,
:P_FILEIDS,
:p_cursor);
END;`, {
p_name: {
2025-04-02 13:03:48 +05:30
val: body.p_name,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_lookupcode: {
2025-04-02 13:03:48 +05:30
val: body.p_lookupcode,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_address1: {
2025-04-02 13:03:48 +05:30
val: body.p_address1,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_address2: {
2025-04-02 13:03:48 +05:30
val: body.p_address2,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_city: {
2025-04-02 13:03:48 +05:30
val: body.p_city,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_state: {
2025-04-02 13:03:48 +05:30
val: body.p_state,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_zip: {
2025-04-02 13:03:48 +05:30
val: body.p_zip,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_country: {
2025-04-02 13:03:48 +05:30
val: body.p_country,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_issuingregion: {
2025-04-02 13:03:48 +05:30
val: body.p_issuingregion,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_replacementregion: {
2025-04-02 13:03:48 +05:30
val: body.p_replacementregion,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_bondsurety: {
2025-04-02 13:03:48 +05:30
val: body.p_bondsurety,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_cargopolicyno: {
2025-04-02 13:03:48 +05:30
val: body.p_cargopolicyno,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_cargosurety: {
2025-04-02 13:03:48 +05:30
val: body.p_cargosurety,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_user_id: {
2025-04-02 13:03:48 +05:30
val: body.p_user_id,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
P_NOTES: {
2025-04-02 13:03:48 +05:30
val: body.P_NOTES,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
P_FILEIDS: {
2025-04-02 13:03:48 +05:30
val: body.P_FILEIDS,
2025-03-25 17:10:33 +05:30
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) {
2025-04-02 13:03:48 +05:30
2025-03-25 17:10:33 +05:30
return { error: err.message }
} finally { }
}
2025-04-02 13:03:48 +05:30
async updateServiceProvider(body: UpdateServiceProviderDTO) {
2025-03-25 17:10:33 +05:30
let connection;
try {
2025-04-02 13:03:48 +05:30
2025-03-25 17:10:33 +05:30
connection = await this.oracleDBService.getConnection()
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_NOTES,
:P_FILEIDS,
:p_cursor);
END;`, {
p_spid: {
2025-04-02 13:03:48 +05:30
val: body.p_spid,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_NUMBER
},
p_name: {
2025-04-02 13:03:48 +05:30
val: body.p_name,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_lookupcode: {
2025-04-02 13:03:48 +05:30
val: body.p_lookupcode,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_address1: {
2025-04-02 13:03:48 +05:30
val: body.p_address1,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_address2: {
2025-04-02 13:03:48 +05:30
val: body.p_address2,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_city: {
2025-04-02 13:03:48 +05:30
val: body.p_city,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_state: {
2025-04-02 13:03:48 +05:30
val: body.p_state,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_zip: {
2025-04-02 13:03:48 +05:30
val: body.p_zip,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_country: {
2025-04-02 13:03:48 +05:30
val: body.p_country,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_issuingregion: {
2025-04-02 13:03:48 +05:30
val: body.p_issuingregion,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_replacementregion: {
2025-04-02 13:03:48 +05:30
val: body.p_replacementregion,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_bondsurety: {
2025-04-02 13:03:48 +05:30
val: body.p_bondsurety,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_cargopolicyno: {
2025-04-02 13:03:48 +05:30
val: body.p_cargopolicyno,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_cargosurety: {
2025-04-02 13:03:48 +05:30
val: body.p_cargosurety,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
p_user_id: {
2025-04-02 13:03:48 +05:30
val: body.p_user_id,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
P_NOTES: {
2025-04-02 13:03:48 +05:30
val: body.P_NOTES,
2025-03-25 17:10:33 +05:30
type: oracledb.DB_TYPE_VARCHAR
},
P_FILEIDS: {
2025-04-02 13:03:48 +05:30
val: body.P_FILEIDS,
2025-03-25 17:10:33 +05:30
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) {
2025-04-02 13:03:48 +05:30
2025-03-25 17:10:33 +05:30
return { error: err.message }
} finally { }
}
async getAllServiceproviders() {
let connection;
let rows = [];
try {
2025-04-02 13:03:48 +05:30
2025-03-25 17:10:33 +05:30
connection = await this.oracleDBService.getConnection()
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) {
2025-04-02 13:03:48 +05:30
const cursor = result.outBinds.p_cursor;
2025-03-25 17:10:33 +05:30
let rowsBatch;
do {
2025-04-02 13:03:48 +05:30
rowsBatch = await cursor.getRows(100);
rows = rows.concat(rowsBatch);
2025-03-25 17:10:33 +05:30
} while (rowsBatch.length > 0);
2025-04-02 13:03:48 +05:30
2025-03-25 17:10:33 +05:30
await cursor.close();
return rows;
} else {
throw new Error('No cursor returned from the stored procedure');
}
} catch (err) {
2025-04-02 13:03:48 +05:30
2025-03-25 17:10:33 +05:30
return { error: err.message }
} finally { }
}
2025-04-02 13:03:48 +05:30
async getServiceproviderByID(body:getSelectedServiceproviderDTO) {
2025-03-25 17:10:33 +05:30
let connection;
let rows = [];
try {
2025-04-02 13:03:48 +05:30
2025-03-25 17:10:33 +05:30
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
2025-04-02 13:03:48 +05:30
USCIB_Managed_Pkg.GetSPbySPID(:p_spid,:p_cursor);
END;`,
2025-03-25 17:10:33 +05:30
{
p_spid: {
2025-04-02 13:03:48 +05:30
val: body.p_spid,
2025-03-25 17:10:33 +05:30
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) {
2025-04-02 13:03:48 +05:30
const cursor = result.outBinds.p_cursor;
2025-03-25 17:10:33 +05:30
let rowsBatch;
do {
2025-04-02 13:03:48 +05:30
rowsBatch = await cursor.getRows(100);
rows = rows.concat(rowsBatch);
2025-03-25 17:10:33 +05:30
} while (rowsBatch.length > 0);
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
}
return rows;
} catch (err) {
2025-04-02 13:03:48 +05:30
2025-03-25 17:10:33 +05:30
return { error: err.message }
} finally { }
}
}