BE/src/oracle/manage-holders/manage-holders.service.ts

611 lines
22 KiB
TypeScript
Raw Normal View History

2025-02-24 10:32:41 +05:30
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';
2025-06-07 14:42:21 +05:30
import { closeOracleDbConnection, fetchCursor, handleError, setEmptyStringsToNull } from 'src/utils/helper';
2025-02-24 10:32:41 +05:30
import {
2025-06-07 14:42:21 +05:30
CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO,
HolderContactActivateOrInactivateDTO, SearchHolderDTO, UpdateHolderContactDTO, UpdateHolderDTO
2025-02-24 10:32:41 +05:30
} from 'src/dto/property.dto';
import { OracleService } from '../oracle.service';
2025-06-07 14:42:21 +05:30
import { BadRequestException } from 'src/exceptions/badRequest.exception';
2025-02-24 10:32:41 +05:30
@Injectable()
export class ManageHoldersService {
private readonly logger = new Logger(ManageHoldersService.name);
constructor(
private readonly oracleDBService: OracleDBService,
private readonly oracleService: OracleService
) { }
2025-02-24 10:32:41 +05:30
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));
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)
2025-02-24 10:32:41 +05:30
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;`,
2025-02-24 10:32:41 +05:30
{
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 },
2025-06-07 14:42:21 +05:30
P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT },
P_HOLDERCURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT },
P_HOLDERCONTACTCURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
2025-02-24 10:32:41 +05:30
},
{ 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 = {
2025-06-07 14:42:21 +05:30
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,
2025-02-24 10:32:41 +05:30
};
const reqBody = JSON.parse(JSON.stringify(body));
setEmptyStringsToNull(reqBody);
2025-06-07 14:42:21 +05:30
const finalBody: UpdateHolderDTO = { ...newBody, ...reqBody };
let connection;
2025-02-24 10:32:41 +05:30
try {
connection = await this.oracleDBService.getConnection();
2025-06-07 14:42:21 +05:30
const 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;`,
2025-02-24 10:32:41 +05:30
{
2025-06-07 14:42:21 +05:30
P_HOLDERID: { VAL: finalBody.P_HOLDERID, TYPE: oracledb.DB_TYPE_NUMBER },
P_SPID: { VAL: finalBody.P_SPID, TYPE: oracledb.DB_TYPE_NUMBER },
P_LOCATIONID: { VAL: finalBody.P_LOCATIONID, 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_CURSOR: { TYPE: oracledb.CURSOR, DIR: oracledb.BIND_OUT }
2025-02-24 10:32:41 +05:30
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
await connection.commit();
2025-06-07 14:42:21 +05:30
const outBinds: any = result.outBinds;
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.");
}
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name);
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
if (fres.length > 0 && fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
2025-02-24 10:32:41 +05:30
}
2025-06-07 14:42:21 +05:30
return { P_cursor: fres };
2025-02-24 10:32:41 +05:30
// return fres
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
2025-06-07 14:42:21 +05:30
2025-02-24 10:32:41 +05:30
GetHolderRecord = async (body: GetHolderDTO) => {
2025-06-07 14:42:21 +05:30
let connection;
2025-02-24 10:32:41 +05:30
try {
connection = await this.oracleDBService.getConnection();
const result: Result<any> = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.GetHolderMaster(
2025-06-07 14:42:21 +05:30
:P_SPID, :P_HOLDERID, :P_CURSOR
2025-02-24 10:32:41 +05:30
);
END;`,
{
2025-06-07 14:42:21 +05:30
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 }
2025-02-24 10:32:41 +05:30
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
2025-06-07 14:42:21 +05:30
const outBinds: any = result.outBinds;
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.");
}
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name);
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
if (fres.length > 0 && fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
2025-02-24 10:32:41 +05:30
}
2025-06-07 14:42:21 +05:30
return { P_CURSOR: fres };
2025-02-24 10:32:41 +05:30
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
2025-06-07 14:42:21 +05:30
2025-02-24 10:32:41 +05:30
UpdateHolderContact = async (body: UpdateHolderContactDTO) => {
const newBody = {
2025-06-07 14:42:21 +05:30
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,
2025-02-24 10:32:41 +05:30
};
const reqBody = JSON.parse(JSON.stringify(body));
setEmptyStringsToNull(reqBody);
const finalBody: UpdateHolderContactDTO = { ...newBody, ...reqBody };
2025-06-07 14:42:21 +05:30
let connection;
2025-02-24 10:32:41 +05:30
try {
connection = await this.oracleDBService.getConnection();
const result: Result<any> = await connection.execute(
2025-06-07 14:42:21 +05:30
`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
);
2025-02-24 10:32:41 +05:30
END;`,
{
2025-06-07 14:42:21 +05:30
P_HOLDERCONTACTID: { val: finalBody.P_HOLDERCONTACTID, type: oracledb.DB_TYPE_NUMBER },
P_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER },
P_FIRSTNAME: { val: finalBody.P_FIRSTNAME, type: oracledb.DB_TYPE_NVARCHAR },
P_LASTNAME: { val: finalBody.P_LASTNAME, type: oracledb.DB_TYPE_NVARCHAR },
P_MIDDLEINITIAL: { val: finalBody.P_MIDDLEINITIAL, type: oracledb.DB_TYPE_NVARCHAR },
P_TITLE: { val: finalBody.P_TITLE, type: oracledb.DB_TYPE_NVARCHAR },
P_PHONENO: { val: finalBody.P_PHONENO, type: oracledb.DB_TYPE_NVARCHAR },
P_MOBILENO: { val: finalBody.P_MOBILENO, type: oracledb.DB_TYPE_NVARCHAR },
P_FAXNO: { val: finalBody.P_FAXNO, type: oracledb.DB_TYPE_NVARCHAR },
P_EMAILADDRESS: { val: finalBody.P_EMAILADDRESS, type: oracledb.DB_TYPE_NVARCHAR },
P_USERID: { val: finalBody.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
2025-02-24 10:32:41 +05:30
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
await connection.commit();
// let fres = await result.outBinds.P_cursor.getRows();
2025-06-07 14:42:21 +05:30
const outBinds: any = result.outBinds;
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.");
}
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name);
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
if (fres.length > 0 && fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
2025-02-24 10:32:41 +05:30
}
2025-06-07 14:42:21 +05:30
return { P_cursor: fres };
2025-02-24 10:32:41 +05:30
// return fres
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
2025-06-07 14:42:21 +05:30
2025-02-24 10:32:41 +05:30
GetHolderContacts = async (body: GetHolderDTO) => {
2025-06-07 14:42:21 +05:30
let connection;
2025-02-24 10:32:41 +05:30
try {
connection = await this.oracleDBService.getConnection();
const result: Result<any> = await connection.execute(
`BEGIN
2025-06-07 14:42:21 +05:30
MANAGEHOLDER_PKG.GetHolderContacts(
:P_SPID, :P_HOLDERID, :P_CURSOR
);
END;`,
2025-02-24 10:32:41 +05:30
{
2025-06-07 14:42:21 +05:30
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 }
2025-02-24 10:32:41 +05:30
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
2025-06-07 14:42:21 +05:30
const outBinds: any = result.outBinds;
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.");
}
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name);
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
if (fres.length > 0 && fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
2025-02-24 10:32:41 +05:30
}
2025-06-07 14:42:21 +05:30
return { P_CURSOR: fres };
2025-02-24 10:32:41 +05:30
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
2025-06-07 14:42:21 +05:30
2025-02-24 10:32:41 +05:30
InactivateHolder = async (body: HolderActivateOrInactivateDTO) => {
2025-06-07 14:42:21 +05:30
let connection;
2025-02-24 10:32:41 +05:30
try {
connection = await this.oracleDBService.getConnection();
const result: Result<any> = await connection.execute(
`BEGIN
2025-06-07 14:42:21 +05:30
ManageHolder_Pkg.InactivateHolder(
:P_SPID, :P_HOLDERID, :P_USERID, :P_CURSOR
);
END;`,
2025-02-24 10:32:41 +05:30
{
2025-06-07 14:42:21 +05:30
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 }
2025-02-24 10:32:41 +05:30
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
2025-06-07 14:42:21 +05:30
await connection.commit();
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
const outBinds: any = result.outBinds;
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, ManageHoldersService.name);
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
if (fres.length > 0 && fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
2025-02-24 10:32:41 +05:30
}
2025-06-07 14:42:21 +05:30
return { P_CURSOR: fres };
2025-02-24 10:32:41 +05:30
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
2025-06-07 14:42:21 +05:30
2025-02-24 10:32:41 +05:30
ReactivateHolder = async (body: HolderActivateOrInactivateDTO) => {
2025-06-07 14:42:21 +05:30
let connection;
2025-02-24 10:32:41 +05:30
try {
connection = await this.oracleDBService.getConnection();
const result: Result<any> = await connection.execute(
`BEGIN
2025-06-07 14:42:21 +05:30
ManageHolder_Pkg.ReactivateHolder(
:P_SPID, :P_HOLDERID, :P_USERID, :P_CURSOR
);
END;`,
2025-02-24 10:32:41 +05:30
{
2025-06-07 14:42:21 +05:30
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 }
2025-02-24 10:32:41 +05:30
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
2025-06-07 14:42:21 +05:30
await connection.commit();
const outBinds: any = result.outBinds;
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.");
}
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name);
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
if (fres.length > 0 && fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
2025-02-24 10:32:41 +05:30
}
2025-06-07 14:42:21 +05:30
return { P_CURSOR: fres };
2025-02-24 10:32:41 +05:30
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
2025-06-07 14:42:21 +05:30
2025-02-24 10:32:41 +05:30
InactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => {
2025-06-07 14:42:21 +05:30
let connection;
2025-02-24 10:32:41 +05:30
try {
connection = await this.oracleDBService.getConnection();
const result: Result<any> = await connection.execute(
`BEGIN
ManageHolder_Pkg.InactivateHolderContact(
2025-06-07 14:42:21 +05:30
:P_SPID, :P_HOLDERCONTACTID, :P_USERID, :P_CURSOR
2025-02-24 10:32:41 +05:30
);
END;`,
{
2025-06-07 14:42:21 +05:30
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 }
2025-02-24 10:32:41 +05:30
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
2025-06-07 14:42:21 +05:30
await connection.commit();
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
const outBinds: any = result.outBinds;
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, ManageHoldersService.name);
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
if (fres.length > 0 && fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
2025-02-24 10:32:41 +05:30
}
2025-06-07 14:42:21 +05:30
return { P_CURSOR: fres };
2025-02-24 10:32:41 +05:30
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
2025-06-07 14:42:21 +05:30
2025-02-24 10:32:41 +05:30
ReactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => {
2025-06-07 14:42:21 +05:30
let connection;
2025-02-24 10:32:41 +05:30
try {
connection = await this.oracleDBService.getConnection();
const result: Result<any> = await connection.execute(
`BEGIN
2025-06-07 14:42:21 +05:30
ManageHolder_Pkg.ReactivateHolderContact(
:P_SPID, :P_HOLDERCONTACTID, :P_USERID, :P_CURSOR
);
END;`,
2025-02-24 10:32:41 +05:30
{
2025-06-07 14:42:21 +05:30
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 }
2025-02-24 10:32:41 +05:30
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
2025-06-07 14:42:21 +05:30
await connection.commit();
const outBinds: any = result.outBinds;
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.");
}
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageHoldersService.name);
2025-02-24 10:32:41 +05:30
2025-06-07 14:42:21 +05:30
if (fres.length > 0 && fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
2025-02-24 10:32:41 +05:30
}
2025-06-07 14:42:21 +05:30
return { P_CURSOR: fres };
2025-02-24 10:32:41 +05:30
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
SearchHolder = async (body: SearchHolderDTO) => {
let connection;
try {
connection = await this.oracleDBService.getConnection();
const result: Result<any> = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.SearchHolder(
:P_SPID, :P_HOLDERNAME, :P_CURSOR
);
END;`,
{
P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER },
P_HOLDERCONTACTID: { val: body.P_HOLDERNAME, type: oracledb.DB_TYPE_NUMBER },
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
await connection.commit();
const outBinds: any = result.outBinds;
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, ManageHoldersService.name);
if (fres.length > 0 && fres[0].ERRORMESG) {
this.logger.warn(fres[0].ERRORMESG);
throw new BadRequestException(fres[0].ERRORMESG)
}
return fres;
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
}
2025-02-24 10:32:41 +05:30
}