2025-03-25 17:10:33 +05:30
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
import { OracleDBService } from 'src/db/db.service';
|
2025-04-02 13:29:06 +05:30
|
|
|
import * as oracledb from 'oracledb';
|
2025-04-02 13:03:48 +05:30
|
|
|
import {
|
2025-04-07 11:36:24 +05:30
|
|
|
getSPAllContactsDTO,
|
2025-04-02 13:29:06 +05:30
|
|
|
getSPDefaultcontactDTO,
|
|
|
|
|
inactivateSPContactDTO,
|
|
|
|
|
InsertSPContactsDTO,
|
|
|
|
|
setSPDefaultcontactDTO,
|
|
|
|
|
UpdateSPContactsDTO,
|
2025-04-02 13:03:48 +05:30
|
|
|
} from './sp-contacts.dto';
|
2025-03-25 17:10:33 +05:30
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class SpContactsService {
|
2025-04-07 11:36:24 +05:30
|
|
|
constructor(private readonly oracleDBService: OracleDBService) { }
|
2025-04-02 13:29:06 +05:30
|
|
|
|
|
|
|
|
async insertSPContacts(body: InsertSPContactsDTO) {
|
|
|
|
|
let connection;
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
|
if (!connection) {
|
|
|
|
|
throw new Error('No DB Connected');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await connection.execute(
|
|
|
|
|
`BEGIN
|
2025-03-25 17:10:33 +05:30
|
|
|
USCIB_Managed_Pkg.InsertSPContacts(
|
|
|
|
|
:p_spid,
|
|
|
|
|
:p_defcontactflag,
|
|
|
|
|
:p_firstname,
|
|
|
|
|
:p_lastname,
|
|
|
|
|
:P_MIDDLEINITIAL,
|
|
|
|
|
:p_title,
|
|
|
|
|
:p_phoneno,
|
|
|
|
|
:p_mobileno,
|
|
|
|
|
:p_faxno,
|
|
|
|
|
:p_emailaddress,
|
|
|
|
|
:p_user_id,
|
|
|
|
|
:p_cursor);
|
2025-04-02 13:29:06 +05:30
|
|
|
END;`,
|
|
|
|
|
{
|
|
|
|
|
p_spid: {
|
|
|
|
|
val: body.p_spid,
|
|
|
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
|
|
|
},
|
|
|
|
|
p_defcontactflag: {
|
|
|
|
|
val: body.p_defcontactflag,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_firstname: {
|
|
|
|
|
val: body.p_firstname,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_lastname: {
|
|
|
|
|
val: body.p_lastname,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
P_MIDDLEINITIAL: {
|
|
|
|
|
val: body.P_MIDDLEINITIAL,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_title: {
|
|
|
|
|
val: body.p_title,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_phoneno: {
|
|
|
|
|
val: body.p_phoneno,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_mobileno: {
|
|
|
|
|
val: body.p_mobileno,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_faxno: {
|
|
|
|
|
val: body.p_faxno,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_emailaddress: {
|
|
|
|
|
val: body.p_emailaddress,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_user_id: {
|
|
|
|
|
val: body.p_user_id,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_cursor: {
|
|
|
|
|
type: oracledb.CURSOR,
|
|
|
|
|
dir: oracledb.BIND_OUT,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await connection.commit();
|
|
|
|
|
|
|
|
|
|
const fres = await result.outBinds.p_cursor.getRows();
|
|
|
|
|
|
|
|
|
|
return fres;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
if (err instanceof Error) {
|
|
|
|
|
return { error: err.message };
|
|
|
|
|
} else {
|
|
|
|
|
return { error: 'An unknown error occurred' };
|
|
|
|
|
}
|
2025-03-25 17:10:33 +05:30
|
|
|
}
|
2025-04-02 13:29:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async setSPDefaultcontact(body: setSPDefaultcontactDTO) {
|
|
|
|
|
let connection;
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
|
if (!connection) {
|
|
|
|
|
throw new Error('No DB Connected');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await connection.execute(
|
|
|
|
|
`BEGIN
|
2025-03-25 17:10:33 +05:30
|
|
|
USCIB_Managed_Pkg.SetDefaultContact(:p_spcontactid);
|
|
|
|
|
END;`,
|
2025-04-02 13:29:06 +05:30
|
|
|
{
|
|
|
|
|
p_spcontactid: {
|
|
|
|
|
val: body.p_spcontactid,
|
|
|
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await connection.commit();
|
|
|
|
|
|
|
|
|
|
return 'SP executed successfully';
|
|
|
|
|
} catch (err) {
|
|
|
|
|
if (err instanceof Error) {
|
|
|
|
|
return { error: err.message };
|
|
|
|
|
} else {
|
|
|
|
|
return { error: 'An unknown error occurred' };
|
|
|
|
|
}
|
2025-03-25 17:10:33 +05:30
|
|
|
}
|
2025-04-02 13:29:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async updateSPContacts(body: UpdateSPContactsDTO) {
|
|
|
|
|
let connection;
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
|
if (!connection) {
|
|
|
|
|
throw new Error('No DB Connected');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await connection.execute(
|
|
|
|
|
`BEGIN
|
2025-03-25 17:10:33 +05:30
|
|
|
USCIB_Managed_Pkg.UpdateSPContacts(
|
|
|
|
|
:p_spcontactid,
|
|
|
|
|
:p_firstname,
|
|
|
|
|
:p_lastname,
|
|
|
|
|
:P_MIDDLEINITIAL,
|
|
|
|
|
:p_title,
|
|
|
|
|
:p_phoneno,
|
|
|
|
|
:p_mobileno,
|
|
|
|
|
:p_faxno,
|
|
|
|
|
:p_emailaddress,
|
|
|
|
|
:p_user_id,
|
|
|
|
|
:p_cursor);
|
2025-04-02 13:29:06 +05:30
|
|
|
END;`,
|
|
|
|
|
{
|
|
|
|
|
p_spcontactid: {
|
|
|
|
|
val: body.p_spcontactid,
|
|
|
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
|
|
|
},
|
|
|
|
|
p_firstname: {
|
|
|
|
|
val: body.p_firstname,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_lastname: {
|
|
|
|
|
val: body.p_lastname,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
P_MIDDLEINITIAL: {
|
|
|
|
|
val: body.P_MIDDLEINITIAL,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_title: {
|
|
|
|
|
val: body.p_title,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_phoneno: {
|
|
|
|
|
val: body.p_phoneno,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_mobileno: {
|
|
|
|
|
val: body.p_mobileno,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_faxno: {
|
|
|
|
|
val: body.p_faxno,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_emailaddress: {
|
|
|
|
|
val: body.p_emailaddress,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_user_id: {
|
|
|
|
|
val: body.p_user_id,
|
|
|
|
|
type: oracledb.DB_TYPE_VARCHAR,
|
|
|
|
|
},
|
|
|
|
|
p_cursor: {
|
|
|
|
|
type: oracledb.CURSOR,
|
|
|
|
|
dir: oracledb.BIND_OUT,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
outFormat: oracledb.OUT_FORMAT_OBJECT,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await connection.commit();
|
|
|
|
|
|
|
|
|
|
const fres = await result.outBinds.p_cursor.getRows();
|
|
|
|
|
|
|
|
|
|
return fres;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
if (err instanceof Error) {
|
|
|
|
|
return { error: err.message };
|
|
|
|
|
} else {
|
|
|
|
|
return { error: 'An unknown error occurred' };
|
|
|
|
|
}
|
2025-03-25 17:10:33 +05:30
|
|
|
}
|
2025-04-02 13:29:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async inactivateSPContact(body: inactivateSPContactDTO) {
|
|
|
|
|
let connection;
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
|
if (!connection) {
|
|
|
|
|
throw new Error('No DB Connected');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await connection.execute(
|
|
|
|
|
`BEGIN
|
2025-03-25 17:10:33 +05:30
|
|
|
USCIB_Managed_Pkg.InActivateSPContacts(:p_spcontactid);
|
2025-04-02 13:29:06 +05:30
|
|
|
END;`,
|
|
|
|
|
{
|
|
|
|
|
p_spcontactid: {
|
|
|
|
|
val: body.p_spcontactid,
|
|
|
|
|
type: oracledb.DB_TYPE_NUMBER,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await connection.commit();
|
|
|
|
|
|
|
|
|
|
return 'SP executed successfully';
|
|
|
|
|
} catch (err) {
|
|
|
|
|
if (err instanceof Error) {
|
|
|
|
|
return { error: err.message };
|
|
|
|
|
} else {
|
|
|
|
|
return { error: 'An unknown error occurred' };
|
|
|
|
|
}
|
2025-03-25 17:10:33 +05:30
|
|
|
}
|
2025-04-02 13:29:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getSPDefaultcontacts(body: getSPDefaultcontactDTO) {
|
|
|
|
|
let connection;
|
|
|
|
|
let rows = [];
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
|
if (!connection) {
|
|
|
|
|
throw new Error('No DB Connected');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await connection.execute(
|
|
|
|
|
`BEGIN
|
2025-03-25 17:10:33 +05:30
|
|
|
USCIB_Managed_Pkg.GetSPDefaultContacts(:p_SPid,:p_cursor);
|
|
|
|
|
END;`,
|
2025-04-02 13:29:06 +05:30
|
|
|
{
|
|
|
|
|
p_SPid: {
|
|
|
|
|
val: body.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;
|
|
|
|
|
let rowsBatch;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
rowsBatch = await cursor.getRows(100);
|
|
|
|
|
rows = rows.concat(rowsBatch);
|
|
|
|
|
} while (rowsBatch.length > 0);
|
|
|
|
|
|
|
|
|
|
await cursor.close();
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error('No cursor returned from the stored procedure');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
if (err instanceof Error) {
|
|
|
|
|
return { error: err.message };
|
|
|
|
|
} else {
|
|
|
|
|
return { error: 'An unknown error occurred' };
|
|
|
|
|
}
|
2025-03-25 17:10:33 +05:30
|
|
|
}
|
2025-04-02 13:29:06 +05:30
|
|
|
}
|
2025-04-07 11:36:24 +05:30
|
|
|
|
|
|
|
|
async getSPAllContacts(body: getSPAllContactsDTO) {
|
|
|
|
|
|
|
|
|
|
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.GetSPAllContacts(:p_SPid,:p_cursor);
|
|
|
|
|
END;`,
|
|
|
|
|
{
|
|
|
|
|
p_SPid: {
|
|
|
|
|
val: body.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;
|
|
|
|
|
let rowsBatch;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
rowsBatch = await cursor.getRows(100);
|
|
|
|
|
rows = rows.concat(rowsBatch);
|
|
|
|
|
} while (rowsBatch.length > 0);
|
|
|
|
|
|
|
|
|
|
await cursor.close();
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error('No cursor returned from the stored procedure');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
if (err instanceof Error) {
|
|
|
|
|
return { error: err.message };
|
|
|
|
|
} else {
|
|
|
|
|
return { error: 'An unknown error occurred' };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-25 17:10:33 +05:30
|
|
|
}
|