BE/src/oracle/manage-holders/manage-holders.service.ts
2025-06-05 17:06:18 +05:30

1202 lines
36 KiB
TypeScript

import { Injectable, Logger } from '@nestjs/common';
import { OracleDBService } from 'src/db/db.service';
import * as oracledb from 'oracledb';
import { Connection, Result } from 'oracledb';
import { InternalServerException } from 'src/exceptions/internalServerError.exception';
import { closeOracleDbConnection, fetchCursor, handleError } from 'src/utils/helper';
import {
CONTACTSTABLE_ROW_DTO, CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO,
HolderContactActivateOrInactivateDTO, UpdateHolderContactDTO, UpdateHolderDTO
} from 'src/dto/property.dto';
@Injectable()
export class ManageHoldersService {
private readonly logger = new Logger(ManageHoldersService.name);
constructor(private readonly oracleDBService: OracleDBService) { }
// CreateHoldersX = async (body: CreateHoldersDTO) => {
// const newBody = {
// p_spid: null,
// p_clientlocationid: null,
// p_holderno: null,
// p_holdertype: null,
// p_uscibmemberflag: null,
// p_govagencyflag: null,
// p_holdername: null,
// p_namequalifier: null,
// p_addlname: null,
// p_address1: null,
// p_address2: null,
// p_city: null,
// p_state: null,
// p_zip: null,
// p_country: null,
// p_userid: null,
// p_contactstable: null,
// };
// const reqBody = JSON.parse(JSON.stringify(body));
// function setEmptyStringsToNull(obj) {
// Object.keys(obj).forEach((key) => {
// if (typeof obj[key] === 'object' && obj[key] !== null) {
// setEmptyStringsToNull(obj[key]);
// } else if (obj[key] === '') {
// obj[key] = null;
// }
// });
// }
// setEmptyStringsToNull(reqBody);
// const finalBody: CreateHoldersDTO = { ...newBody, ...reqBody };
// let connection: Connection | undefined = undefined;
// let p_holdercursor_rows = [];
// let p_holdercontactcursor_rows = [];
// try {
// connection = await this.oracleDBService.getConnection();
// if (!connection) {
// throw new InternalServerException();
// }
// // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CONTACT%'`);
// // return { res:res.rows };
// // const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY');
// const CONTACTSTABLE = await connection.getDbObjectClass(
// 'CARNETSYS.CONTACTSTABLE',
// );
// // Check if GLTABLE is a constructor
// if (typeof CONTACTSTABLE !== 'function') {
// throw new Error('CONTACTSTABLE is not a constructor');
// }
// async function CREATECONTACTSTABLE_INSTANCE(
// connection,
// FirstName,
// LastName,
// MiddleInitial,
// Title,
// EmailAddress,
// PhoneNo,
// MobileNo,
// FaxNo,
// ) {
// const result: Result<any> = await connection.execute(
// `SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`,
// {
// FirstName,
// LastName,
// MiddleInitial,
// Title,
// EmailAddress,
// PhoneNo,
// MobileNo,
// FaxNo,
// },
// );
// return result.rows?.[0]?.[0] ?? [];
// }
// const CONTACTSARRAY = finalBody.P_CONTACTSTABLE
// ? await Promise.all(
// finalBody.p_contactstable.map(async (x: p_contactstableDTO) => {
// return await CREATECONTACTSTABLE_INSTANCE(
// connection,
// x.FirstName,
// x.LastName,
// x.MiddleInitial,
// x.Title,
// x.EmailAddress,
// x.PhoneNo,
// x.MobileNo,
// x.FaxNo,
// );
// }),
// )
// : [];
// // Create an instance of GLTABLE
// const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY);
// const result: Result<any> = await connection.execute(
// `BEGIN
// MANAGEHOLDER_PKG.CreateHolderData(
// :p_spid,
// :p_clientlocationid,
// :p_holderno,
// :p_holdertype,
// :p_uscibmemberflag,
// :p_govagencyflag,
// :p_holdername,
// :p_namequalifier,
// :p_addlname,
// :p_address1,
// :p_address2,
// :p_city,
// :p_state,
// :p_zip,
// :p_country,
// :p_userid,
// :p_contactstable,
// :p_holdercursor,
// :p_holdercontactcursor
// );
// END;`,
// {
// p_spid: {
// val: finalBody.p_spid ? finalBody.p_spid : null,
// type: oracledb.DB_TYPE_NUMBER,
// },
// p_clientlocationid: {
// val: finalBody.p_clientlocationid
// ? finalBody.p_clientlocationid
// : null,
// type: oracledb.DB_TYPE_NUMBER,
// },
// p_holderno: {
// val: finalBody.p_holderno ? finalBody.p_holderno : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_holdertype: {
// val: finalBody.p_holdertype ? finalBody.p_holdertype : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_uscibmemberflag: {
// val: finalBody.p_uscibmemberflag
// ? finalBody.p_uscibmemberflag
// : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_govagencyflag: {
// val: finalBody.p_govagencyflag ? finalBody.p_govagencyflag : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_holdername: {
// val: finalBody.p_holdername ? finalBody.p_holdername : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_namequalifier: {
// val: finalBody.p_namequalifier ? finalBody.p_namequalifier : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_addlname: {
// val: finalBody.p_addlname ? finalBody.p_addlname : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_address1: {
// val: finalBody.p_address1 ? finalBody.p_address1 : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_address2: {
// val: finalBody.p_address2 ? finalBody.p_address2 : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_city: {
// val: finalBody.p_city ? finalBody.p_city : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_state: {
// val: finalBody.p_state ? finalBody.p_state : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_zip: {
// val: finalBody.p_zip ? finalBody.p_zip : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_country: {
// val: finalBody.p_country ? finalBody.p_country : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_userid: {
// val: finalBody.p_userid ? finalBody.p_userid : null,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_contactstable: {
// val: CONTACTSTABLE_INSTANCE,
// type: oracledb.DB_TYPE_NVARCHAR,
// },
// p_holdercursor: {
// type: oracledb.CURSOR,
// dir: oracledb.BIND_OUT,
// },
// p_holdercontactcursor: {
// type: oracledb.CURSOR,
// dir: oracledb.BIND_OUT,
// },
// },
// {
// outFormat: oracledb.OUT_FORMAT_OBJECT,
// },
// );
// await connection.commit();
// // let fres = await result.outBinds.P_cursor.getRows();
// if (result.outBinds && result.outBinds.p_holdercursor) {
// const cursor = result.outBinds.p_holdercursor;
// let rowsBatch;
// do {
// rowsBatch = await cursor.getRows(100);
// p_holdercursor_rows = p_holdercursor_rows.concat(rowsBatch);
// } while (rowsBatch.length > 0);
// await cursor.close();
// } else {
// throw new BadRequestException();
// }
// if (result.outBinds && result.outBinds.p_holdercontactcursor) {
// const cursor = result.outBinds.p_holdercontactcursor;
// let rowsBatch;
// do {
// rowsBatch = await cursor.getRows(100);
// p_holdercontactcursor_rows =
// p_holdercontactcursor_rows.concat(rowsBatch);
// } while (rowsBatch.length > 0);
// await cursor.close();
// } else {
// throw new BadRequestException();
// }
// return {
// p_holdercursor: p_holdercursor_rows,
// p_holdercontactcursor: p_holdercontactcursor_rows,
// };
// // return fres
// } catch (error) {
// if (error instanceof BadRequestException) {
// this.logger.warn(error.message);
// throw error;
// }
// this.logger.error('CreateHolders failed', error.stack || error);
// throw new InternalServerException();
// } finally {
// if (connection) {
// try {
// await connection.close();
// } catch (closeErr) {
// this.logger.error('Failed to close DB connection', closeErr);
// }
// }
// }
// };
async CreateHolders(body: CreateHoldersDTO) {
const newBody = {
P_SPID: null,
P_CLIENTLOCATIONID: null,
P_HOLDERNO: null,
P_HOLDERTYPE: null,
P_USCIBMEMBERFLAG: null,
P_GOVAGENCYFLAG: null,
P_HOLDERNAME: null,
P_NAMEQUALIFIER: null,
P_ADDLNAME: null,
P_ADDRESS1: null,
P_ADDRESS2: null,
P_CITY: null,
P_STATE: null,
P_ZIP: null,
P_COUNTRY: null,
P_USERID: null,
P_CONTACTSTABLE: null,
};
const reqBody = JSON.parse(JSON.stringify(body));
function setEmptyStringsToNull(obj) {
Object.keys(obj).forEach((key) => {
if (typeof obj[key] === 'object' && obj[key] !== null) {
setEmptyStringsToNull(obj[key]);
} else if (obj[key] === '') {
obj[key] = null;
}
});
}
setEmptyStringsToNull(reqBody);
const finalBody: CreateHoldersDTO = { ...newBody, ...reqBody };
let connection;
try {
connection = await this.oracleDBService.getConnection();
const CONTACTSTABLE = await connection.getDbObjectClass(
'CARNETSYS.CONTACTSTABLE',
);
// Check if GLTABLE is a constructor
if (typeof CONTACTSTABLE !== 'function') {
throw new Error('CONTACTSTABLE is not a constructor');
}
async function CREATECONTACTSTABLE_INSTANCE(
connection,
FirstName,
LastName,
MiddleInitial,
Title,
EmailAddress,
PhoneNo,
MobileNo,
FaxNo,
) {
const result: Result<any> = await connection.execute(
`SELECT CARNETSYS.CONTACTSARRAY(:FirstName, :LastName, :MiddleInitial, :Title, :EmailAddress, :PhoneNo, :MobileNo, :FaxNo) FROM dual`,
{
FirstName,
LastName,
MiddleInitial,
Title,
EmailAddress,
PhoneNo,
MobileNo,
FaxNo,
},
);
return result.rows?.[0]?.[0] ?? [];
}
const CONTACTSARRAY = finalBody.P_CONTACTSTABLE
? await Promise.all(
finalBody.P_CONTACTSTABLE.map(async (x: CONTACTSTABLE_ROW_DTO) => {
return await CREATECONTACTSTABLE_INSTANCE(
connection,
x.P_FIRSTNAME,
x.P_LASTNAME,
x.P_MIDDLEINITIAL,
x.P_TITLE,
x.P_EMAILADDRESS,
x.P_PHONENO,
x.P_MOBILENO,
x.P_FAXNO,
);
}),
)
: [];
// Create an instance of GLTABLE
const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY);
const result = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.CreateHolderData(
:p_spid,
:p_clientlocationid,
:p_holderno,
:p_holdertype,
:p_uscibmemberflag,
:p_govagencyflag,
:p_holdername,
:p_namequalifier,
:p_addlname,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_userid,
:p_contactstable,
:p_holdercursor,
:p_holdercontactcursor
);
END;`,
{
P_SPID: {
val: finalBody.P_SPID ? finalBody.P_SPID : null,
type: oracledb.DB_TYPE_NUMBER,
},
P_CLIENTLOCATIONID: {
val: finalBody.P_CLIENTLOCATIONID ? finalBody.P_CLIENTLOCATIONID : null,
type: oracledb.DB_TYPE_NUMBER,
},
P_HOLDERNO: {
val: finalBody.P_HOLDERNO ? finalBody.P_HOLDERNO : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_HOLDERTYPE: {
val: finalBody.P_HOLDERTYPE ? finalBody.P_HOLDERTYPE : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_USCIBMEMBERFLAG: {
val: finalBody.P_USCIBMEMBERFLAG ? finalBody.P_USCIBMEMBERFLAG : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_GOVAGENCYFLAG: {
val: finalBody.P_GOVAGENCYFLAG ? finalBody.P_GOVAGENCYFLAG : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_HOLDERNAME: {
val: finalBody.P_HOLDERNAME ? finalBody.P_HOLDERNAME : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_NAMEQUALIFIER: {
val: finalBody.P_NAMEQUALIFIER ? finalBody.P_NAMEQUALIFIER : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_ADDLNAME: {
val: finalBody.P_ADDLNAME ? finalBody.P_ADDLNAME : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_ADDRESS1: {
val: finalBody.P_ADDRESS1 ? finalBody.P_ADDRESS1 : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_ADDRESS2: {
val: finalBody.P_ADDRESS2 ? finalBody.P_ADDRESS2 : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_CITY: {
val: finalBody.P_CITY ? finalBody.P_CITY : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_STATE: {
val: finalBody.P_STATE ? finalBody.P_STATE : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_ZIP: {
val: finalBody.P_ZIP ? finalBody.P_ZIP : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_COUNTRY: {
val: finalBody.P_COUNTRY ? finalBody.P_COUNTRY : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_USERID: {
val: finalBody.P_USERID ? finalBody.P_USERID : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_CONTACTSTABLE: {
val: CONTACTSTABLE_INSTANCE,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_HOLDERCURSOR: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT,
},
P_HOLDERCONTACTCURSOR: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT,
},
},
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
);
await connection.commit();
const outBinds: any = result.outBinds;
if (!outBinds?.P_HOLDERCURSOR || !outBinds?.P_HOLDERCONTACTCURSOR) {
this.logger.error('One or more expected cursors are missing from stored procedure output.');
throw new InternalServerException("Incomplete data received from the database.");
}
// if (!outBinds?.P_CURSOR) {
// this.logger.error('One or more expected cursors are missing from stored procedure output.');
// throw new InternalServerException("Incomplete data received from the database.");
// }
// const fres: any = await fetchCursor(outBinds.P_CURSOR, ParamTableService.name);
// if (fres.length > 0 && fres[0].ERRORMESG) {
// this.logger.warn(fres[0].ERRORMESG);
// throw new BadRequestException(fres[0].ERRORMESG)
// }
return {
holderDetails: await fetchCursor(outBinds.P_HOLDERCURSOR, ManageHoldersService.name),
holderContactDetails: await fetchCursor(outBinds.P_HOLDERCONTACTCURSOR, ManageHoldersService.name),
}
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
}
UpdateHolder = async (body: UpdateHolderDTO) => {
const newBody = {
p_holderid: null,
p_spid: null,
p_locationid: null,
p_holderno: null,
p_holdertype: null,
p_uscibmemberflag: null,
p_govagencyflag: null,
p_holdername: null,
p_namequalifier: null,
p_addlname: null,
p_address1: null,
p_address2: null,
p_city: null,
p_state: null,
p_zip: null,
p_country: null,
p_userid: null,
};
const reqBody = JSON.parse(JSON.stringify(body));
function setEmptyStringsToNull(obj) {
Object.keys(obj).forEach((key) => {
if (typeof obj[key] === 'object' && obj[key] !== null) {
setEmptyStringsToNull(obj[key]);
} else if (obj[key] === '') {
obj[key] = null;
}
});
}
setEmptyStringsToNull(reqBody);
const finalBody = { ...newBody, ...reqBody };
let connection: Connection | undefined = undefined;
let P_cursor_rows = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
}
const result: Result<any> = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.UpdateHolders(
:p_holderid,
:p_spid,
:p_locationid,
:p_holderno,
:p_holdertype,
:p_uscibmemberflag,
:p_govagencyflag,
:p_holdername,
:p_namequalifier,
:p_addlname,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_userid,
:P_cursor
);
END;`,
{
p_holderid: {
val: finalBody.p_holderid ? finalBody.p_holderid : null,
type: oracledb.DB_TYPE_NUMBER,
},
p_spid: {
val: finalBody.p_spid ? finalBody.p_spid : null,
type: oracledb.DB_TYPE_NUMBER,
},
p_locationid: {
val: finalBody.p_locationid ? finalBody.p_locationid : null,
type: oracledb.DB_TYPE_NUMBER,
},
p_holderno: {
val: finalBody.p_holderno ? finalBody.p_holderno : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_holdertype: {
val: finalBody.p_holdertype ? finalBody.p_holdertype : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_uscibmemberflag: {
val: finalBody.p_uscibmemberflag
? finalBody.p_uscibmemberflag
: null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_govagencyflag: {
val: finalBody.p_govagencyflag ? finalBody.p_govagencyflag : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_holdername: {
val: finalBody.p_holdername ? finalBody.p_holdername : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_namequalifier: {
val: finalBody.p_namequalifier ? finalBody.p_namequalifier : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_addlname: {
val: finalBody.p_addlname ? finalBody.p_addlname : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_address1: {
val: finalBody.p_address1 ? finalBody.p_address1 : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_address2: {
val: finalBody.p_address2 ? finalBody.p_address2 : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_city: {
val: finalBody.p_city ? finalBody.p_city : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_state: {
val: finalBody.p_state ? finalBody.p_state : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_zip: {
val: finalBody.p_zip ? finalBody.p_zip : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_country: {
val: finalBody.p_country ? finalBody.p_country : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_userid: {
val: finalBody.p_userid ? finalBody.p_userid : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
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();
if (result.outBinds && result.outBinds.P_cursor) {
const cursor = result.outBinds.P_cursor;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
P_cursor_rows = P_cursor_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
}
return { P_cursor: P_cursor_rows };
// return fres
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
GetHolderRecord = async (body: GetHolderDTO) => {
let connection: Connection | undefined = undefined;
let P_CURSOR_rows = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
}
const result: Result<any> = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.GetHolderMaster(
:P_SPID,
:P_HOLDERID,
:P_CURSOR
);
END;`,
{
P_SPID: {
val: body.P_SPID,
type: oracledb.DB_TYPE_NUMBER,
},
P_HOLDERID: {
val: body.P_HOLDERID,
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);
P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
return { P_CURSOR: P_CURSOR_rows };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
UpdateHolderContact = async (body: UpdateHolderContactDTO) => {
const newBody = {
p_holdercontactid: null,
p_spid: null,
p_firstname: null,
p_lastname: null,
p_middleinitial: null,
p_title: null,
p_phone: null,
p_mobile: null,
p_fax: null,
p_emailaddress: null,
p_userid: null,
};
const reqBody = JSON.parse(JSON.stringify(body));
function setEmptyStringsToNull(obj) {
Object.keys(obj).forEach((key) => {
if (typeof obj[key] === 'object' && obj[key] !== null) {
setEmptyStringsToNull(obj[key]);
} else if (obj[key] === '') {
obj[key] = null;
}
});
}
setEmptyStringsToNull(reqBody);
const finalBody: UpdateHolderContactDTO = { ...newBody, ...reqBody };
let connection: Connection | undefined = undefined;
let P_cursor_rows = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
}
const result: Result<any> = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.UpdateHolders(
:P_HOLDERCONTACTID,
:P_SPID,
:P_FIRSTNAME,
:P_LASTNAME,
:P_MIDDLEINITIAL,
:P_TITLE,
:P_PHONENO,
:P_MOBILENO,
:P_FAXNO,
:P_EMAILADDRESS,
:P_USERID,
:P_CURSOR
);
END;`,
{
P_HOLDERCONTACTID: {
val: finalBody.P_HOLDERCONTACTID ? finalBody.P_HOLDERCONTACTID : null,
type: oracledb.DB_TYPE_NUMBER,
},
P_SPID: {
val: finalBody.P_SPID ? finalBody.P_SPID : null,
type: oracledb.DB_TYPE_NUMBER,
},
P_FIRSTNAME: {
val: finalBody.P_FIRSTNAME ? finalBody.P_FIRSTNAME : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_LASTNAME: {
val: finalBody.P_LASTNAME ? finalBody.P_LASTNAME : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_MIDDLEINITIAL: {
val: finalBody.P_MIDDLEINITIAL ? finalBody.P_MIDDLEINITIAL : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_TITLE: {
val: finalBody.P_TITLE ? finalBody.P_TITLE : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_PHONENO: {
val: finalBody.P_PHONENO ? finalBody.P_PHONENO : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_MOBILENO: {
val: finalBody.P_MOBILENO ? finalBody.P_MOBILENO : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_FAXNO: {
val: finalBody.P_FAXNO ? finalBody.P_FAXNO : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_EMAILADDRESS: {
val: finalBody.P_EMAILADDRESS ? finalBody.P_EMAILADDRESS : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
P_USERID: {
val: finalBody.P_USERID ? finalBody.P_USERID : null,
type: oracledb.DB_TYPE_NVARCHAR,
},
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();
if (result.outBinds && result.outBinds.P_cursor) {
const cursor = result.outBinds.P_cursor;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
P_cursor_rows = P_cursor_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
}
return { P_cursor: P_cursor_rows };
// return fres
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
GetHolderContacts = async (body: GetHolderDTO) => {
let connection: Connection | undefined = undefined;
let P_CURSOR_rows = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
}
const result: Result<any> = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.GetHolderContacts(
:P_SPID,
:P_HOLDERID,
:P_CURSOR
);
END;`,
{
P_SPID: {
val: body.P_SPID,
type: oracledb.DB_TYPE_NUMBER,
},
P_HOLDERID: {
val: body.P_HOLDERID,
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);
P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
return { P_CURSOR: P_CURSOR_rows };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
InactivateHolder = async (body: HolderActivateOrInactivateDTO) => {
let connection: Connection | undefined = undefined;
let P_CURSOR_rows = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
}
const result: Result<any> = await connection.execute(
`BEGIN
ManageHolder_Pkg.InactivateHolder(
:P_SPID,
:P_HOLDERID,
:P_USERID,
:P_CURSOR
);
END;`,
{
P_SPID: {
val: body.P_SPID,
type: oracledb.DB_TYPE_NUMBER,
},
P_HOLDERID: {
val: body.P_HOLDERID,
type: oracledb.DB_TYPE_NUMBER,
},
P_USERID: {
val: body.P_USERID,
type: oracledb.DB_TYPE_NVARCHAR,
},
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);
P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
return { P_CURSOR: P_CURSOR_rows };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
ReactivateHolder = async (body: HolderActivateOrInactivateDTO) => {
let connection: Connection | undefined = undefined;
let P_CURSOR_rows = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
}
const result: Result<any> = await connection.execute(
`BEGIN
ManageHolder_Pkg.ReactivateHolder(
:P_SPID,
:P_HOLDERID,
:P_USERID,
:P_CURSOR
);
END;`,
{
P_SPID: {
val: body.P_SPID,
type: oracledb.DB_TYPE_NUMBER,
},
P_HOLDERID: {
val: body.P_HOLDERID,
type: oracledb.DB_TYPE_NUMBER,
},
P_USERID: {
val: body.P_USERID,
type: oracledb.DB_TYPE_NVARCHAR,
},
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);
P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
return { P_CURSOR: P_CURSOR_rows };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
InactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => {
let connection: Connection | undefined = undefined;
let P_CURSOR_rows = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
}
const result: Result<any> = await connection.execute(
`BEGIN
ManageHolder_Pkg.InactivateHolderContact(
:P_SPID,
:P_HOLDERCONTACTID,
:P_USERID,
:P_CURSOR
);
END;`,
{
P_SPID: {
val: body.P_SPID,
type: oracledb.DB_TYPE_NUMBER,
},
P_HOLDERCONTACTID: {
val: body.P_HOLDERCONTACTID,
type: oracledb.DB_TYPE_NUMBER,
},
P_USERID: {
val: body.P_USERID,
type: oracledb.DB_TYPE_NVARCHAR,
},
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);
P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
return { P_CURSOR: P_CURSOR_rows };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
ReactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => {
let connection: Connection | undefined = undefined;
let P_CURSOR_rows = [];
try {
connection = await this.oracleDBService.getConnection();
if (!connection) {
throw new Error('No DB Connected');
}
const result: Result<any> = await connection.execute(
`BEGIN
ManageHolder_Pkg.ReactivateHolderContact(
:P_SPID,
:P_HOLDERCONTACTID,
:P_USERID,
:P_CURSOR
);
END;`,
{
P_SPID: {
val: body.P_SPID,
type: oracledb.DB_TYPE_NUMBER,
},
P_HOLDERCONTACTID: {
val: body.P_HOLDERCONTACTID,
type: oracledb.DB_TYPE_NUMBER,
},
P_USERID: {
val: body.P_USERID,
type: oracledb.DB_TYPE_NVARCHAR,
},
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);
P_CURSOR_rows = P_CURSOR_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
return { P_CURSOR: P_CURSOR_rows };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
}