183 lines
5.8 KiB
TypeScript
183 lines
5.8 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { OracleDBService } from 'src/db/db.service';
|
|
import { CreateClientDataDTO, GetPreparersDTO } from './manage-clients.dto';
|
|
|
|
@Injectable()
|
|
export class ManageClientsService {
|
|
constructor(private readonly oracleDBService: OracleDBService) { }
|
|
|
|
CreateClientData = async (body: CreateClientDataDTO) => {
|
|
|
|
|
|
|
|
let 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
|
|
}
|
|
|
|
let 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: CreateClientDataDTO = { ...newBody, ...reqBody };
|
|
|
|
let connection;
|
|
let p_holdercursor_rows = [];
|
|
let p_holdercontactcursor_rows = [];
|
|
try {
|
|
|
|
connection = await this.oracleDBService.getConnection()
|
|
if (!connection) {
|
|
throw new Error('No DB Connected')
|
|
}
|
|
|
|
let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CLIENT%'`);
|
|
|
|
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 = 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 = await connection.execute(
|
|
// `BEGIN
|
|
// MANAGEHOLDER_PKG.CreateHolderData(
|
|
// :p_spid,
|
|
// );
|
|
// END;`,
|
|
// {
|
|
// p_spid: {
|
|
// val: finalBody.p_spid ? finalBody.p_spid : null,
|
|
// type: oracledb.DB_TYPE_NUMBER
|
|
// },
|
|
|
|
// p_holderno: {
|
|
// val: finalBody.p_holderno ? finalBody.p_holderno : null,
|
|
// type: oracledb.DB_TYPE_NVARCHAR
|
|
// },
|
|
// p_holdercontactcursor: {
|
|
// type: oracledb.CURSOR,
|
|
// dir: oracledb.BIND_OUT
|
|
// }
|
|
// }, {
|
|
// outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
// }
|
|
// );
|
|
|
|
// await connection.commit();
|
|
|
|
// 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 Error('No cursor returned from the stored procedure');
|
|
// }
|
|
|
|
// return { p_holdercursor: p_holdercursor_rows, p_holdercontactcursor: p_holdercontactcursor_rows };
|
|
|
|
|
|
} catch (err) {
|
|
console.error('Error fetching users: ', err);
|
|
return { error: err.message }
|
|
} finally { }
|
|
|
|
}
|
|
|
|
UpdateClient = async () => {
|
|
|
|
}
|
|
|
|
UpdateClientContacts = async () => {
|
|
|
|
}
|
|
|
|
UpdateClientLocations = async () => {
|
|
|
|
}
|
|
|
|
CreateClientContact = async () => {
|
|
|
|
}
|
|
|
|
CreateClientLocation = async () => {
|
|
|
|
}
|
|
|
|
GetPreparers = async (reqQuery: GetPreparersDTO) => {
|
|
return reqQuery
|
|
}
|
|
|
|
GetPreparerByClientid = async () => {
|
|
|
|
}
|
|
|
|
GetPreparerContactsByClientid = async () => {
|
|
|
|
}
|
|
|
|
GetPreparerLocByClientid = async () => {
|
|
|
|
}
|
|
}
|