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'; import { OracleService } from '../oracle.service'; @Injectable() export class ManageHoldersService { private readonly logger = new Logger(ManageHoldersService.name); constructor( private readonly oracleDBService: OracleDBService, private readonly oracleService: OracleService ) { } // 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 = 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 = 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_INSTANCE = await this.oracleService.get_CONTACTS_TABLE_INSTANCE(finalBody) 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, type: oracledb.DB_TYPE_NUMBER }, P_CLIENTLOCATIONID: { val: finalBody.P_CLIENTLOCATIONID, type: oracledb.DB_TYPE_NUMBER }, P_HOLDERNO: { val: finalBody.P_HOLDERNO, type: oracledb.DB_TYPE_NVARCHAR }, P_HOLDERTYPE: { val: finalBody.P_HOLDERTYPE, type: oracledb.DB_TYPE_NVARCHAR }, P_USCIBMEMBERFLAG: { val: finalBody.P_USCIBMEMBERFLAG, type: oracledb.DB_TYPE_NVARCHAR }, P_GOVAGENCYFLAG: { val: finalBody.P_GOVAGENCYFLAG, type: oracledb.DB_TYPE_NVARCHAR }, P_HOLDERNAME: { val: finalBody.P_HOLDERNAME, type: oracledb.DB_TYPE_NVARCHAR }, P_NAMEQUALIFIER: { val: finalBody.P_NAMEQUALIFIER, type: oracledb.DB_TYPE_NVARCHAR }, P_ADDLNAME: { val: finalBody.P_ADDLNAME, type: oracledb.DB_TYPE_NVARCHAR }, P_ADDRESS1: { val: finalBody.P_ADDRESS1, type: oracledb.DB_TYPE_NVARCHAR }, P_ADDRESS2: { val: finalBody.P_ADDRESS2, type: oracledb.DB_TYPE_NVARCHAR }, P_CITY: { val: finalBody.P_CITY, type: oracledb.DB_TYPE_NVARCHAR }, P_STATE: { val: finalBody.P_STATE, type: oracledb.DB_TYPE_NVARCHAR }, P_ZIP: { val: finalBody.P_ZIP, type: oracledb.DB_TYPE_NVARCHAR }, P_COUNTRY: { val: finalBody.P_COUNTRY, type: oracledb.DB_TYPE_NVARCHAR }, P_USERID: { val: finalBody.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: 'CARNETSYS.CONTACTSTABLE' }, 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = 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) } }; }