From 6fc32672f576db6d98f22c64661d840e2fc9c533 Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Sat, 29 Mar 2025 10:28:51 +0530 Subject: [PATCH] updated array to handle --- src/oracle/home-page/home-page.service.ts | 38 +------------------ .../manage-holders/manage-holders.service.ts | 31 +++++++++++---- 2 files changed, 25 insertions(+), 44 deletions(-) diff --git a/src/oracle/home-page/home-page.service.ts b/src/oracle/home-page/home-page.service.ts index 9c9d013..0d187e8 100644 --- a/src/oracle/home-page/home-page.service.ts +++ b/src/oracle/home-page/home-page.service.ts @@ -471,13 +471,11 @@ export class HomePageService { // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name IN ('GLARRAY', 'GLTABLE')`) - let GLARRAY = await connection.getDbObjectClass('CARNETSYS.GLARRAY'); + // let GLARRAY = await connection.getDbObjectClass('CARNETSYS.GLARRAY'); const GLTABLE = await connection.getDbObjectClass('CARNETSYS.GLTABLE'); - const CARNETCOUNTRYARRAY = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYARRAY'); + // const CARNETCOUNTRYARRAY = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYARRAY'); const CARNETCOUNTRYTABLE = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYTABLE'); - console.log("here ------------ 2"); - // Check if GLTABLE is a constructor if (typeof GLTABLE !== 'function') { throw new Error('GLTABLE is not a constructor'); @@ -487,45 +485,17 @@ export class HomePageService { throw new Error('CARNETCOUNTRYTABLE is not a constructor'); } - console.log("here ------------ 3"); - // console.log(finalBody); - - let k = new GLARRAY(1, 'Description for itemno 1', 2500, 20,12,'LBS','US') - - // return {k} - - - const GLTABLE_ARRAY = finalBody.p_gltable ? await Promise.all(finalBody.p_gltable.map(async (x:p_gltableDTO) => { return await createGLArrayInstance(connection, x.ItemNo, x.ItemDescription, x.ItemValue, x.Noofpieces, x.ItemWeight, x.ItemWeightUOM, x.GoodsOriginCountry); })) : []; - console.log("here ------------ 4"); - const CARNETCOUNTRYTABLE_ARRAY = finalBody.p_countrytable ? await Promise.all(finalBody.p_countrytable.map(async (x) => { return await createCarnetCountryArrayInstance(connection, x.VisitTransitInd, x.CountryCode, x.NoOfTimesEntLeave); })) : []; - console.log("CARNETCOUNTRYTABLE_ARRAY : ", CARNETCOUNTRYTABLE_ARRAY[0], CARNETCOUNTRYTABLE_ARRAY[1]); - - - console.log("here ------------ 5"); - - // Create an instance of GLTABLE const GLTABLE_INSTANCE = new GLTABLE(GLTABLE_ARRAY); const CARNETCOUNTRYTABLE_INSTANCE = new CARNETCOUNTRYTABLE(CARNETCOUNTRYTABLE_ARRAY); - console.log(finalBody); - console.log(GLTABLE_INSTANCE); - console.log(CARNETCOUNTRYTABLE_INSTANCE); - - - - - console.log("here ------------ 6"); - - // return { GLTABLE_INSTANCE, CARNETCOUNTRYTABLE_INSTANCE }; - const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.SaveCarnetApplication( @@ -679,8 +649,6 @@ export class HomePageService { ); 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; @@ -698,8 +666,6 @@ export class HomePageService { return rows; - // return fres - } catch (err) { console.error('Error fetching users: ', err); return { error: err.message } diff --git a/src/oracle/manage-holders/manage-holders.service.ts b/src/oracle/manage-holders/manage-holders.service.ts index 2a280c7..927a132 100644 --- a/src/oracle/manage-holders/manage-holders.service.ts +++ b/src/oracle/manage-holders/manage-holders.service.ts @@ -56,14 +56,11 @@ export class ManageHoldersService { throw new Error('No DB Connected') } - // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name IN ('GLARRAY', 'GLTABLE')`) // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name LIKE '%CONTACT%'`); // return { res:res.rows }; - // contactstable - - const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY'); + // const CONTACTSARRAY = await connection.getDbObjectClass('CARNETSYS.CONTACTSARRAY'); const CONTACTSTABLE = await connection.getDbObjectClass('CARNETSYS.CONTACTSTABLE'); // Check if GLTABLE is a constructor @@ -71,12 +68,29 @@ export class ManageHoldersService { throw new Error('CONTACTSTABLE is not a constructor'); } - const CONTACTSTABLE_ARRAY = finalBody.p_contactstable ? finalBody.p_contactstable.map((x: p_contactstableDTO) => { - return new CONTACTSARRAY(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]; + } + + 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(CONTACTSTABLE_ARRAY); + const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY); const result = await connection.execute( `BEGIN @@ -184,6 +198,7 @@ export class ManageHoldersService { outFormat: oracledb.OUT_FORMAT_OBJECT } ); + await connection.commit(); // let fres = await result.outBinds.P_cursor.getRows();