resolved bind mismatch

This commit is contained in:
Kallesh B S 2025-04-01 09:40:49 +05:30
parent 4888ec28fe
commit cedbee4ab4
2 changed files with 607 additions and 96 deletions

View File

@ -1,6 +1,6 @@
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { ManageClientsService } from './manage-clients.service';
import { CreateClientDataDTO, GetPreparersDTO } from './manage-clients.dto';
import { CreateClientDataDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO } from './manage-clients.dto';
import { ApiTags } from '@nestjs/swagger';
@Controller('oracle')
@ -14,23 +14,27 @@ export class ManageClientsController {
return this.manageClientsService.CreateClientData(body);
}
UpdateClient = async () =>{
@ApiTags('Manage Clients - Oracle')
@Post('UpdateClient')
async UpdateClient(@Body() body:UpdateClientDTO){
return this.manageClientsService.UpdateClient(body);
}
@ApiTags('Manage Clients - Oracle')
@Post('UpdateClientContacts')
UpdateClientContacts(@Body() body:UpdateClientContactsDTO){
return this.manageClientsService.UpdateClientContacts(body);
}
UpdateClientLocations(){
}
UpdateClientContacts = async () =>{
CreateClientContact(){
}
UpdateClientLocations = async () =>{
}
CreateClientContact = async () =>{
}
CreateClientLocation = async () =>{
CreateClientLocation(){
}
@ -40,15 +44,15 @@ export class ManageClientsController {
return await this.manageClientsService.GetPreparers(query)
}
GetPreparerByClientid = async () =>{
GetPreparerByClientid(){
}
GetPreparerContactsByClientid = async () =>{
GetPreparerContactsByClientid(){
}
GetPreparerLocByClientid = async () =>{
GetPreparerLocByClientid(){
}
}

View File

@ -1,6 +1,8 @@
import { Injectable } from '@nestjs/common';
import { OracleDBService } from 'src/db/db.service';
import { CreateClientDataDTO, GetPreparersDTO } from './manage-clients.dto';
import { CreateClientDataDTO, GetPreparersDTO, p_clientlocaddresstableDTO, UpdateClientContactsDTO, UpdateClientDTO } from './manage-clients.dto';
import { p_contactstableDTO } from '../manage-holders/manage-holders.dto';
import * as oracledb from 'oracledb'
@Injectable()
export class ManageClientsService {
@ -8,26 +10,21 @@ export class ManageClientsService {
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_clientname": null,
"p_lookupcode": null,
"p_address1": null,
"p_address2": null,
"p_city": null,
"p_state": null,
"p_zip": null,
"p_country": null,
"p_issuingregion": null,
"p_revenuelocation": null,
"p_userid": null,
"p_contactstable": null
"p_contactstable": null,
"p_clientlocaddresstable": null
}
let reqBody = JSON.parse(JSON.stringify(body));
@ -47,8 +44,10 @@ export class ManageClientsService {
const finalBody: CreateClientDataDTO = { ...newBody, ...reqBody };
let connection;
let p_holdercursor_rows = [];
let p_holdercontactcursor_rows = [];
let p_clientcursor_rows = [];
let p_clientcontactcursor_rows = [];
let p_clientloccursor_rows = [];
try {
connection = await this.oracleDBService.getConnection()
@ -56,85 +55,216 @@ export class ManageClientsService {
throw new Error('No DB Connected')
}
let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CLIENT%'`);
// let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CLIENT%'`);
return { res:res.rows };
// return { res:res.rows };
// const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY');
// const CONTACTSTABLE = await connection.getDbObjectClass('CARNETSYS.CONTACTSTABLE');
const CONTACTSTABLE = await connection.getDbObjectClass('CARNETSYS.CONTACTSTABLE');
// const CLIENTLOCADDRESSARRAY = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSARRAY');
const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSTABLE');
// // Check if GLTABLE is a constructor
// if (typeof CONTACTSTABLE !== 'function') {
// throw new Error('CONTACTSTABLE is not a constructor');
// }
// Check if CONTACTSTABLE 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];
// }
// Check if CLIENTLOCADDRESSTABLE is a constructor
if (typeof CLIENTLOCADDRESSTABLE !== 'function') {
throw new Error('CLIENTLOCADDRESSTABLE is not a constructor');
}
// 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);
// })) : [];
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];
}
async function CREATECLIENTLOCADDRESSTABLE_INSTANCE(connection, Nameof, Address1, Address2, City, State, Zip, Country) {
const result = await connection.execute(
`SELECT CARNETSYS.CLIENTLOCADDRESSARRAY(:Nameof, :Address1, :Address2, :City, :State, :Zip, :Country) FROM dual`,
{
Nameof,
Address1,
Address2,
City,
State,
Zip,
Country
}
);
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);
})) : [];
const CLIENTLOCADDRESSARRAY = finalBody.p_clientlocaddresstable ? await Promise.all(finalBody.p_clientlocaddresstable.map(async (x: p_clientlocaddresstableDTO) => {
return await CREATECLIENTLOCADDRESSTABLE_INSTANCE(connection, x.Nameof, x.Address1, x.Address2, x.City, x.State, x.Zip, x.Country);
})) : [];
// Create an instance of GLTABLE
// const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY);
const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY);
const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE(CLIENTLOCADDRESSARRAY);
// 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
// },
// return {CONTACTSTABLE_INSTANCE, CLIENTLOCADDRESSTABLE_INSTANCE}
// 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
// }
// );
const result = await connection.execute(
`BEGIN
MANAGEPREPARER_PKG.CreateClientData(
:p_spid,
:p_clientname,
:p_lookupcode,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_issuingregion,
:p_revenuelocation,
:p_userid,
:p_contactstable,
:p_clientlocaddresstable,
:p_clientcursor,
:p_clientcontactcursor,
:p_clientloccursor
);
END;`,
{
p_spid: {
val: finalBody.p_spid ? finalBody.p_spid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_clientname: {
val: finalBody.p_clientname ? finalBody.p_clientname : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_lookupcode: {
val: finalBody.p_lookupcode ? finalBody.p_lookupcode : 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_issuingregion: {
val: finalBody.p_issuingregion ? finalBody.p_issuingregion : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_revenuelocation: {
val: finalBody.p_revenuelocation ? finalBody.p_revenuelocation : 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_OBJECT
},
p_clientlocaddresstable: {
val: CLIENTLOCADDRESSTABLE_INSTANCE,
type: oracledb.DB_TYPE_OBJECT
},
p_clientcursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_clientcontactcursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_clientloccursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
}
}, {
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
// await connection.commit();
await connection.commit();
// if (result.outBinds && result.outBinds.p_holdercursor) {
// const cursor = result.outBinds.p_holdercursor;
// let rowsBatch;
if (result.outBinds && result.outBinds.p_clientcursor) {
const cursor = result.outBinds.p_clientcursor;
let rowsBatch;
// do {
// rowsBatch = await cursor.getRows(100);
// p_holdercursor_rows = p_holdercursor_rows.concat(rowsBatch);
// } while (rowsBatch.length > 0);
do {
rowsBatch = await cursor.getRows(100);
p_clientcursor_rows = p_clientcursor_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
// await cursor.close();
// } else {
// throw new Error('No cursor returned from the stored procedure');
// }
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 };
if (result.outBinds && result.outBinds.p_clientcontactcursor) {
const cursor = result.outBinds.p_clientcontactcursor;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_clientcontactcursor_rows = p_clientcontactcursor_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
}
if (result.outBinds && result.outBinds.p_clientloccursor) {
const cursor = result.outBinds.p_clientloccursor;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_clientloccursor_rows = p_clientloccursor_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
}
return { p_clientcursor: p_clientcursor_rows, p_clientcontactcursor: p_clientcontactcursor_rows, p_clientloccursor: p_clientloccursor_rows };
} catch (err) {
@ -144,11 +274,276 @@ export class ManageClientsService {
}
UpdateClient = async () => {
UpdateClient = async (body: UpdateClientDTO) => {
let newBody = {
"p_spid": null,
"p_clientid": null,
"p_preparername": null,
"p_address1": null,
"p_address2": null,
"p_city": null,
"p_state": null,
"p_zip": null,
"p_country": null,
"p_revenuelocation": null,
"p_userid": null
}
UpdateClientContacts = async () => {
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: UpdateClientDTO = { ...newBody, ...reqBody };
let connection;
let p_cursor_rows = [];
try {
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
MANAGEPREPARER_PKG.UpdateClient(
:p_spid,
:p_clientid,
:p_preparername,
:p_address1,
:p_address2,
:p_city,
:p_state,
:p_zip,
:p_country,
:p_revenuelocation,
:p_userid,
:p_cursor
);
END;`,
{
p_spid: {
val: finalBody.p_spid ? finalBody.p_spid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_clientid: {
val: finalBody.p_clientid ? finalBody.p_clientid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_preparername: {
val: finalBody.p_preparername ? finalBody.p_preparername : 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_revenuelocation: {
val: finalBody.p_revenuelocation ? finalBody.p_revenuelocation : 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();
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 };
} catch (err) {
console.error('Error fetching users: ', err);
return { error: err.message }
} finally { }
}
UpdateClientContacts = async (body: UpdateClientContactsDTO) => {
let newBody = {
"p_spid": null,
"p_clientcontactid": null,
"p_firstname": null,
"p_lastname": null,
"p_middleinitial": null,
"p_title": null,
"p_phone": null,
"p_fax": null,
"p_mobileno": null,
"p_emailaddress": null,
"p_userid": 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: UpdateClientContactsDTO = { ...newBody, ...reqBody };
let connection;
let P_cursor_rows = [];
try {
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
MANAGEPREPARER_PKG.UpdateClientContacts(
:p_spid,
:p_clientcontactid,
:p_firstname,
:p_lastname,
:p_middleinitial,
:p_title,
:p_phone,
:p_fax,
:p_mobileno,
:p_emailaddress,
:p_userid,
:P_cursor
);
END;`,
{
p_spid: {
val: finalBody.p_spid ? finalBody.p_spid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_clientcontactid: {
val: finalBody.p_clientcontactid ? finalBody.p_clientcontactid : 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_phone: {
val: finalBody.p_phone ? finalBody.p_phone : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_fax: {
val: finalBody.p_fax ? finalBody.p_fax : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_mobileno: {
val: finalBody.p_mobileno ? finalBody.p_mobileno : 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();
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 };
} catch (err) {
console.error('Error fetching users: ', err);
return { error: err.message }
} finally { }
}
@ -164,8 +559,120 @@ export class ManageClientsService {
}
GetPreparers = async (reqQuery: GetPreparersDTO) => {
return reqQuery
GetPreparers = async (body: GetPreparersDTO) => {
let connection;
let p_maincursor_rows = [];
let p_contactscursor_rows = [];
let p_locationcursor_rows = [];
try {
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
MANAGEPREPARER_PKG.GetPreparers(
:p_spid,
:p_name,
:p_lookupcode,
:p_city,
:p_state,
:p_status,
:p_maincursor,
:p_contactscursor,
:p_locationcursor
);
END;`,
{
p_spid: {
val: body.p_spid,
type: oracledb.DB_TYPE_NUMBER,
},
p_name: {
val: body.p_name,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_lookupcode: {
val: body.p_lookupcode,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_city: {
val: body.p_city,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_state: {
val: body.p_state,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_status: {
val: body.p_status,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_maincursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_contactscursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_locationcursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
}
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
if (result.outBinds && result.outBinds.p_maincursor) {
const cursor = result.outBinds.p_maincursor;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_maincursor_rows = p_maincursor_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_contactscursor) {
const cursor = result.outBinds.p_contactscursor;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_contactscursor_rows = p_contactscursor_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_locationcursor) {
const cursor = result.outBinds.p_locationcursor;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_locationcursor_rows = p_locationcursor_rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
return { p_maincursor: p_maincursor_rows, p_contactscursor: p_contactscursor_rows, p_locationcursor: p_locationcursor_rows };
} catch (err) {
console.error('Error fetching users: ', err);
return { error: err.message }
} finally { }
}
GetPreparerByClientid = async () => {