BE/src/oracle/manage-holders/manage-holders.service.ts
2025-07-08 17:52:07 +05:30

679 lines
25 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, setEmptyStringsToNull } from 'src/utils/helper';
import {
CreateHolderContactsDTO,
CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO,
HolderContactActivateOrInactivateDTO, SearchHolderDTO, UpdateHolderContactDTO, UpdateHolderDTO
} from 'src/dto/property.dto';
import { OracleService } from '../oracle.service';
import { BadRequestException } from 'src/exceptions/badRequest.exception';
@Injectable()
export class ManageHoldersService {
private readonly logger = new Logger(ManageHoldersService.name);
constructor(
private readonly oracleDBService: OracleDBService,
private readonly oracleService: OracleService
) { }
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)
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_HOLDERCURSOR
);
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: oracledb.DB_TYPE_OBJECT },
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) {
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_HOLDERCURSOR, ManageHoldersService.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),
// }
// return await fetchCursor(outBinds.P_HOLDERCURSOR, ManageHoldersService.name);
return { statusCode: 201, message: "Created Successfully", ...fres[0] };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
}
async CreateHoldercontact(body: CreateHolderContactsDTO) {
// const CONTACTSTABLE_INSTANCE = await this.oracleService.get_CONTACTS_TABLE_INSTANCE(finalBody)
// P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }
const newBody = {
P_SPID: null,
P_HOLDERID: null,
P_CONTACTSTABLE: null,
P_USERID: null,
};
const reqBody = JSON.parse(JSON.stringify(body));
setEmptyStringsToNull(reqBody);
const finalBody: CreateHolderContactsDTO = { ...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.CreateHoldercontact(
:P_SPID, :P_HOLDERID, :P_CONTACTSTABLE, :P_USERID, :P_CURSOR
);
END;`,
{
P_SPID: { val: finalBody.P_SPID, type: oracledb.DB_TYPE_NUMBER },
P_HOLDERID: { val: finalBody.P_HOLDERID, type: oracledb.DB_TYPE_NUMBER },
P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT },
P_USERID: { val: finalBody.P_USERID, type: oracledb.DB_TYPE_NVARCHAR },
P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT }
},
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
);
await connection.commit();
const outBinds = 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 { statusCode: 201, message: "Created Successfully", ...fres[0] };
} 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));
setEmptyStringsToNull(reqBody);
const finalBody: UpdateHolderDTO = { ...newBody, ...reqBody };
let connection;
try {
connection = await this.oracleDBService.getConnection();
const result = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.UPDATEHOLDER(
: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, 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 }
},
{
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 { statusCode: 200, message: "Updated Successfully", ...fres[0] };
// return fres
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
GetHolderRecord = async (body: GetHolderDTO) => {
let connection;
try {
connection = await this.oracleDBService.getConnection();
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,
},
);
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.length > 0 ? fres[0] : fres;
} 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));
setEmptyStringsToNull(reqBody);
const finalBody: UpdateHolderContactDTO = { ...newBody, ...reqBody };
let connection;
try {
connection = await this.oracleDBService.getConnection();
const result: Result<any> = await connection.execute(
`BEGIN
MANAGEHOLDER_PKG.UpdateHolderContacts(
: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, 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 }
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT,
},
);
await connection.commit();
// let fres = await result.outBinds.P_cursor.getRows();
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 { statusCode: 200, message: "Updated Successfully", ...fres[0] };
// return fres
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
GetHolderContacts = async (body: GetHolderDTO) => {
let connection;
try {
connection = await this.oracleDBService.getConnection();
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,
},
);
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)
}
};
InactivateHolder = async (body: HolderActivateOrInactivateDTO) => {
let connection;
try {
connection = await this.oracleDBService.getConnection();
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,
},
);
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 { statusCode: 200, message: 'Reactivated holder successfully' };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
ReactivateHolder = async (body: HolderActivateOrInactivateDTO) => {
let connection;
try {
connection = await this.oracleDBService.getConnection();
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,
},
);
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 { statusCode: 200, message: 'Reactivated holder successfully' };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
InactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => {
let connection;
try {
connection = await this.oracleDBService.getConnection();
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,
},
);
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 { statusCode: 200, message: 'Inactivated holder contact successfully' };
} catch (error) {
handleError(error, ManageHoldersService.name)
} finally {
await closeOracleDbConnection(connection, ManageHoldersService.name)
}
};
ReactivateHolderContact = async (body: HolderContactActivateOrInactivateDTO) => {
let connection;
try {
connection = await this.oracleDBService.getConnection();
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,
},
);
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 { statusCode: 200, message: 'Reactivated holder contact successfully' };
} 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_HOLDERNAME: { val: body.P_HOLDERNAME, type: oracledb.DB_TYPE_NVARCHAR },
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)
}
}
}