From 76a07a04510de80b7abcf66261e298e060ce6de9 Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Fri, 28 Mar 2025 17:24:52 +0530 Subject: [PATCH] resolved null value in db custom types --- package-lock.json | 8 +-- package.json | 2 +- src/oracle/home-page/home-page.service.ts | 76 ++++++++++++++++++++--- 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 812729f..0f08080 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "@types/jest": "^29.5.14", "@types/mssql": "^9.1.7", "@types/node": "^22.10.7", - "@types/oracledb": "^6.5.3", + "@types/oracledb": "^6.5.4", "@types/supertest": "^6.0.2", "eslint": "^9.18.0", "eslint-config-prettier": "^10.0.1", @@ -3507,9 +3507,9 @@ } }, "node_modules/@types/oracledb": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/@types/oracledb/-/oracledb-6.5.3.tgz", - "integrity": "sha512-qrcKBezSXi8MltjKtYOQTN+tk7YjeiLjLO4SgXuzGvUGmLMkDLWTRJ4OtM3YoW9dzi/tQeUdgatTmOOE3nSAVg==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/@types/oracledb/-/oracledb-6.5.4.tgz", + "integrity": "sha512-aog21Z8stj//MGECcP/ZdwImubmLs5iqWji8xkyPPH5nRz3LTGiXpljQvWRFm76/m+Mgg4NlKegC2J/TTAhK7A==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 2cd6b17..7614dbf 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@types/jest": "^29.5.14", "@types/mssql": "^9.1.7", "@types/node": "^22.10.7", - "@types/oracledb": "^6.5.3", + "@types/oracledb": "^6.5.4", "@types/supertest": "^6.0.2", "eslint": "^9.18.0", "eslint-config-prettier": "^10.0.1", diff --git a/src/oracle/home-page/home-page.service.ts b/src/oracle/home-page/home-page.service.ts index ae1888b..9c9d013 100644 --- a/src/oracle/home-page/home-page.service.ts +++ b/src/oracle/home-page/home-page.service.ts @@ -436,13 +436,48 @@ export class HomePageService { throw new Error('No DB Connected') } + console.log("here ------------ 1"); + + // const res = await connection.execute(`SELECT CARNETSYS.GLARRAY(1, 'Description for itemno 1', 2500, 20, 12, 'LBS', 'US') FROM dual`); + + async function createGLArrayInstance(connection, itemNo, itemDescription, itemValue, noOfPieces, itemWeight, itemWeightUOM, goodsOriginCountry) { + const result = await connection.execute( + `SELECT CARNETSYS.GLARRAY(:itemNo, :itemDescription, :itemValue, :noOfPieces, :itemWeight, :itemWeightUOM, :goodsOriginCountry) FROM dual`, + { + itemNo, + itemDescription, + itemValue, + noOfPieces, + itemWeight, + itemWeightUOM, + goodsOriginCountry + } + ); + return result.rows[0][0]; // Access the first row and first column to get the GLARRAY instance + } + + async function createCarnetCountryArrayInstance(connection, visitTransitInd, countryCode, noOfTimesEntLeave) { + const result = await connection.execute( + `SELECT CARNETSYS.CARNETCOUNTRYARRAY(:visitTransitInd, :countryCode, :noOfTimesEntLeave) FROM dual`, + { + visitTransitInd, + countryCode, + noOfTimesEntLeave + } + ); + return result.rows[0][0]; // Access the first row and first column to get the CARNETCOUNTRYARRAY instance + } + + // let res = await connection.execute(`SELECT owner, type_name FROM all_types WHERE type_name IN ('GLARRAY', 'GLTABLE')`) - const 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 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'); @@ -452,19 +487,44 @@ export class HomePageService { throw new Error('CARNETCOUNTRYTABLE is not a constructor'); } - const GLTABLE_ARRAY = finalBody.p_gltable ? finalBody.p_gltable.map((x: p_gltableDTO) => { - return new GLARRAY(x.ItemNo, x.ItemDescription, x.ItemValue, x.Noofpieces, x.ItemWeight, x.ItemWeightUOM, x.GoodsOriginCountry) - }) : []; + console.log("here ------------ 3"); + // console.log(finalBody); - const CARNETCOUNTRYTABLE_ARRAY = finalBody.p_countrytable ? finalBody.p_countrytable.map((x: p_countrytableDTO) => { - return new CARNETCOUNTRYARRAY(x.VisitTransitInd, x.CountryCode, x.NoOfTimesEntLeave) - }) : []; + 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); - // return { GLTABLE_INSTANCE,CARNETCOUNTRYTABLE_INSTANCE }; + 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