import { Injectable, Logger } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; import * as oracledb from 'oracledb' import { InternalServerException } from 'src/exceptions/internalServerError.exception'; import { closeOracleDbConnection, fetchCursor, handleError, setEmptyStringsToNull } from 'src/utils/helper'; import { CarnetProcessingCenterDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO, CreateApplicationDTO, UpdateExpGoodsAuthRepDTO, AddGenerallistItemsDTO, AddCountriesDTO, UpdateShippingDetailsDTO, CA_UpdateHolderDTO, GetCarnetControlCenterDTO } from 'src/dto/property.dto'; import { OracleService } from '../oracle.service'; @Injectable() export class CarnetApplicationService { private readonly logger = new Logger(CarnetApplicationService.name); constructor( private readonly oracleDBService: OracleDBService, private readonly oracleService: OracleService ) { } // [ CARNETAPPLICATION_PKG ] async SaveCarnetApplication(body: SaveCarnetApplicationDTO) { const newBody = { P_SPID: null, // P_CLIENTID: null, P_LOCATIONID: null, P_USERID: null, // P_HEADERID: null, P_APPLICATIONNAME: null, P_HOLDERID: null, P_COMMERCIALSAMPLEFLAG: null, P_PROFEQUIPMENTFLAG: null, P_EXHIBITIONSFAIRFLAG: null, P_AUTOFLAG: null, P_HORSEFLAG: null, P_AUTHREP: null, P_GLTABLE: null, P_USSETS: null, P_COUNTRYTABLE: null, P_SHIPTOTYPE: null, P_SHIPADDRID: null, P_FORMOFSECURITY: null, P_INSPROTECTION: null, P_LDIPROTECTION: null, P_DELIVERYTYPE: null, P_DELIVERYMETHOD: null, P_PAYMENTMETHOD: null, P_CUSTCOURIERNO: null, P_REFNO: null, P_NOTES: null, }; const reqBody = JSON.parse(JSON.stringify(body)); setEmptyStringsToNull(reqBody); const finalBody = { ...newBody, ...reqBody }; let connection; try { connection = await this.oracleDBService.getConnection(); // const res = await connection.execute(`SELECT CARNETSYS.GLARRAY(1, 'Description for itemno 1', 2500, 20, 12, 'LBS', 'US') FROM dual`); // return res; // const GLTABLE = await connection.getDbObjectClass('CARNETSYS.GLTABLE'); // if (typeof GLTABLE !== 'function') { // throw new InternalServerException('GLTABLE is not a constructor'); // } // async function createGLArrayInstance( // 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, // }, // ); // console.log(result.rows); // return result.rows[0][0]; // } // const GLTABLE_ARRAY: GLTABLE_DTO = { // P_GLTABLE: await Promise.all( // (finalBody.P_GLTABLE ?? []).map(async (x: GLTABLE_ROW_DTO) => { // return await createGLArrayInstance( // x.ITEMNO, // x.ITEMDESCRIPTION, // x.ITEMVALUE, // x.NOOFPIECES, // x.ITEMWEIGHT, // x.ITEMWEIGHTUOM, // x.GOODSORIGINCOUNTRY, // ); // }) // ) // }; // const GLTABLE_INSTANCE = new GLTABLE(GLTABLE_ARRAY.P_GLTABLE ?? []); const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_INSTANCE(finalBody); // const COUNTRYTABLE = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYTABLE'); // if (typeof COUNTRYTABLE !== 'function') { // throw new Error('COUNTRYTABLE is not a constructor'); // } // async function createCarnetCountryArrayInstance( // P_VISISTTRANSITIND, // COUNTRYCODE, // NOOFTIMESENTLEAVE, // ) { // const result = await connection.execute( // `SELECT CARNETSYS.CARNETCOUNTRYARRAY(:P_VISISTTRANSITIND, :COUNTRYCODE, :NOOFTIMESENTLEAVE) FROM dual`, // { // P_VISISTTRANSITIND, // COUNTRYCODE, // NOOFTIMESENTLEAVE, // }, // ); // console.log(result.rows); // return result.rows[0][0]; // } // const COUNTRYTABLE_ARRAY: COUNTRYTABLE_DTO = { // P_COUNTRYTABLE: await Promise.all( // (finalBody.P_COUNTRYTABLE ?? []).map(async (x: COUNTRYTABLE_ROW_DTO) => { // return await createCarnetCountryArrayInstance( // x.P_VISISTTRANSITIND, // x.COUNTRYCODE, // x.NOOFTIMESENTLEAVE, // ); // }) // ) // }; // const COUNTRYTABLE_INSTANCE = new COUNTRYTABLE(COUNTRYTABLE_ARRAY.P_COUNTRYTABLE ?? []); const COUNTRYTABLE_INSTANCE = await this.oracleService.get_COUNTRY_TABLE_INSTANCE(finalBody); // return { aa:GLTABLE_ARRAY, ab:COUNTRYTABLE_ARRAY, a: GLTABLE_INSTANCE, b: COUNTRYTABLE_INSTANCE } const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.SaveCarnetApplication( :P_SPID, :P_CLIENTID, :P_LOCATIONID, :P_USERID, :P_HEADERID, :P_APPLICATIONNAME, :P_HOLDERID, :P_COMMERCIALSAMPLEFLAG, :P_PROFEQUIPMENTFLAG, :P_EXHIBITIONSFAIRFLAG, :P_AUTOFLAG, :P_HORSEFLAG, :P_AUTHREP, :P_GLTABLE, :P_USSETS, :P_COUNTRYTABLE, :P_SHIPTOTYPE, :P_SHIPADDRID, :P_FORMOFSECURITY, :P_INSPROTECTION, :P_LDIPROTECTION, :P_DELIVERYTYPE, :P_DELIVERYMETHOD, :P_PAYMENTMETHOD, :P_CUSTCOURIERNO, :P_REFNO, :P_NOTES, :P_CURSOR ); END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, P_CLIENTID: { val: body.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER }, P_LOCATIONID: { val: body.P_LOCATIONID, type: oracledb.DB_TYPE_NUMBER }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_VARCHAR }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_APPLICATIONNAME: { val: body.P_APPLICATIONNAME, type: oracledb.DB_TYPE_VARCHAR }, P_HOLDERID: { val: body.P_HOLDERID, type: oracledb.DB_TYPE_NUMBER }, P_COMMERCIALSAMPLEFLAG: { val: body.P_COMMERCIALSAMPLEFLAG, type: oracledb.DB_TYPE_VARCHAR }, P_PROFEQUIPMENTFLAG: { val: body.P_PROFEQUIPMENTFLAG, type: oracledb.DB_TYPE_VARCHAR }, P_EXHIBITIONSFAIRFLAG: { val: body.P_EXHIBITIONSFAIRFLAG, type: oracledb.DB_TYPE_VARCHAR }, P_AUTOFLAG: { val: body.P_AUTOFLAG, type: oracledb.DB_TYPE_VARCHAR }, P_HORSEFLAG: { val: body.P_HORSEFLAG, type: oracledb.DB_TYPE_VARCHAR }, P_AUTHREP: { val: body.P_AUTHREP, type: oracledb.DB_TYPE_VARCHAR }, P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, P_USSETS: { val: body.P_USSETS, type: oracledb.DB_TYPE_NUMBER }, // P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: 'CARNETSYS.CARNETCOUNTRYTABLE' }, P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, P_SHIPTOTYPE: { val: body.P_SHIPTOTYPE, type: oracledb.DB_TYPE_VARCHAR }, P_SHIPADDRID: { val: body.P_SHIPADDRID, type: oracledb.DB_TYPE_NUMBER }, P_FORMOFSECURITY: { val: body.P_FORMOFSECURITY, type: oracledb.DB_TYPE_VARCHAR }, P_INSPROTECTION: { val: body.P_INSPROTECTION, type: oracledb.DB_TYPE_VARCHAR }, P_LDIPROTECTION: { val: body.P_LDIPROTECTION, type: oracledb.DB_TYPE_VARCHAR }, P_DELIVERYTYPE: { val: body.P_DELIVERYTYPE, type: oracledb.DB_TYPE_VARCHAR }, P_DELIVERYMETHOD: { val: body.P_DELIVERYMETHOD, type: oracledb.DB_TYPE_VARCHAR }, P_PAYMENTMETHOD: { val: body.P_PAYMENTMETHOD, type: oracledb.DB_TYPE_VARCHAR }, P_CUSTCOURIERNO: { val: body.P_CUSTCOURIERNO, type: oracledb.DB_TYPE_VARCHAR }, P_REFNO: { val: body.P_REFNO, type: oracledb.DB_TYPE_VARCHAR }, P_NOTES: { val: body.P_NOTES, type: oracledb.DB_TYPE_VARCHAR }, P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async TransmitApplicationtoProcess(body: TransmitApplicationtoProcessDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.TransmitApplicationtoProcess( :P_SPID, :P_USERID, :P_HEADERID :P_CURSOR ); END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NUMBER }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async CreateApplication(body: CreateApplicationDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.CreateApplication( :P_SPID, :P_CLIENTID, :P_LOCATIONID, :P_USERID, :P_APPLICATIONNAME, :P_ORDERTYPE, :P_ERRORMESG ); END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, P_CLIENTID: { val: body.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER }, P_LOCATIONID: { val: body.P_LOCATIONID, type: oracledb.DB_TYPE_NUMBER }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_APPLICATIONNAME: { val: body.P_APPLICATIONNAME, type: oracledb.DB_TYPE_NVARCHAR }, P_ORDERTYPE: { val: body.P_ORDERTYPE, type: oracledb.DB_TYPE_NVARCHAR }, P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); await connection.commit(); const outBinds = result.outBinds; if (!outBinds?.P_ERRORMESG) { this.logger.error('One or more expected cursors are missing from stored procedure output.'); throw new InternalServerException("Incomplete data received from the database."); } return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async UpdateHolder(body: CA_UpdateHolderDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.UpdateHolder( :P_HEADERID, :P_HOLDERID, :P_ERRORMESG ); END;`, { P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_HOLDERID: { val: body.P_HOLDERID, type: oracledb.DB_TYPE_NUMBER }, P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); await connection.commit(); const outBinds = result.outBinds; if (!outBinds?.P_ERRORMESG) { this.logger.error('One or more expected cursors are missing from stored procedure output.'); throw new InternalServerException("Incomplete data received from the database."); } return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async UpdateExpGoodsAuthRep(body: UpdateExpGoodsAuthRepDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.UpdateExpGoodsAuthRep( :P_HEADERID, :P_COMMERCIALSAMPLEFLAG, :P_PROFEQUIPMENTFLAG, :P_EXHIBITIONSFAIRFLAG, :P_AUTOFLAG, :P_HORSEFLAG, :P_AUTHREP, :P_ERRORMESG ); END;`, { P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_COMMERCIALSAMPLEFLAG: { val: body.P_COMMERCIALSAMPLEFLAG, type: oracledb.DB_TYPE_NVARCHAR }, P_PROFEQUIPMENTFLAG: { val: body.P_PROFEQUIPMENTFLAG, type: oracledb.DB_TYPE_NVARCHAR }, P_EXHIBITIONSFAIRFLAG: { val: body.P_EXHIBITIONSFAIRFLAG, type: oracledb.DB_TYPE_NVARCHAR }, P_AUTOFLAG: { val: body.P_AUTOFLAG, type: oracledb.DB_TYPE_NVARCHAR }, P_HORSEFLAG: { val: body.P_HORSEFLAG, type: oracledb.DB_TYPE_NVARCHAR }, P_AUTHREP: { val: body.P_AUTHREP, type: oracledb.DB_TYPE_NVARCHAR }, P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR } // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); await connection.commit(); const outBinds = result.outBinds; if (!outBinds?.P_ERRORMESG) { this.logger.error('One or more expected cursors are missing from stored procedure output.'); throw new InternalServerException("Incomplete data received from the database."); } return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async AddGenerallistItems(body: AddGenerallistItemsDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_INSTANCE(body); const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.AddGenerallistItems( :P_HEADERID, :P_GLTABLE, :P_USERID, :P_ERRORMESG ); END;`, { P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }, // P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); await connection.commit(); const outBinds = result.outBinds; if (!outBinds?.P_ERRORMESG) { this.logger.error('One or more expected cursors are missing from stored procedure output.'); throw new InternalServerException("Incomplete data received from the database."); } return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async AddCountries(body: AddCountriesDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const COUNTRYTABLE_INSTANCE = await this.oracleService.get_COUNTRY_TABLE_INSTANCE(body); const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.AddCountries( :P_HEADERID, :P_USSETS, :P_COUNTRYTABLE, :P_USERID, :P_ERRORMESG ); END;`, { P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_USSETS: { val: body.P_USSETS, type: oracledb.DB_TYPE_NUMBER }, P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT, typeName: 'CARNETCOUNTRYTABLE' }, // P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }, // P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); await connection.commit(); const outBinds = result.outBinds; if (!outBinds?.P_ERRORMESG) { this.logger.error('One or more expected cursors are missing from stored procedure output.'); throw new InternalServerException("Incomplete data received from the database."); } return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async UpdateShippingDetails(body: UpdateShippingDetailsDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.UpdateHolder( :P_HEADERID, :P_SHIPTOTYPE, :P_SHIPADDRID, :P_FORMOFSECURITY, :P_INSPROTECTION, :P_LDIPROTECTION, :P_DELIVERYTYPE, :P_DELIVERYMETHOD, :P_PAYMENTMETHOD, :P_CUSTCOURIERNO, :P_REFNO, :P_NOTES, :P_USERID, :P_ERRORMESG ); END;`, { P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_SHIPTOTYPE: { val: body.P_SHIPTOTYPE, type: oracledb.DB_TYPE_NVARCHAR }, P_SHIPADDRID: { val: body.P_SHIPADDRID, type: oracledb.DB_TYPE_NUMBER }, P_FORMOFSECURITY: { val: body.P_FORMOFSECURITY, type: oracledb.DB_TYPE_NVARCHAR }, P_INSPROTECTION: { val: body.P_INSPROTECTION, type: oracledb.DB_TYPE_NVARCHAR }, P_LDIPROTECTION: { val: body.P_LDIPROTECTION, type: oracledb.DB_TYPE_NVARCHAR }, P_DELIVERYTYPE: { val: body.P_DELIVERYTYPE, type: oracledb.DB_TYPE_NVARCHAR }, P_DELIVERYMETHOD: { val: body.P_DELIVERYMETHOD, type: oracledb.DB_TYPE_NVARCHAR }, P_PAYMENTMETHOD: { val: body.P_PAYMENTMETHOD, type: oracledb.DB_TYPE_NVARCHAR }, P_CUSTCOURIERNO: { val: body.P_CUSTCOURIERNO, type: oracledb.DB_TYPE_NVARCHAR }, P_REFNO: { val: body.P_REFNO, type: oracledb.DB_TYPE_NVARCHAR }, P_NOTES: { val: body.P_NOTES, type: oracledb.DB_TYPE_NVARCHAR }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); await connection.commit(); const outBinds = result.outBinds; if (!outBinds?.P_ERRORMESG) { this.logger.error('One or more expected cursors are missing from stored procedure output.'); throw new InternalServerException("Incomplete data received from the database."); } return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } // processing [ PROCESSINGCENTER_PKG ] async ProcessOriginalCarnet(body: CarnetProcessingCenterDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN PROCESSINGCENTER_PKG.ProcessOriginalCarnet( :P_USERID, :P_HEADERID :P_CURSOR ); END;`, { P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NUMBER }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async UpdatePrintCarnet(body: CarnetProcessingCenterDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN PROCESSINGCENTER_PKG.UpdatePrintCarnet( :P_USERID, :P_HEADERID :P_CURSOR ); END;`, { P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NUMBER }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async VoidCarnet(body: CarnetProcessingCenterDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN PROCESSINGCENTER_PKG.VoidCarnet( :P_USERID, :P_HEADERID :P_CURSOR ); END;`, { P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NUMBER }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async DuplicateCarnet(body: CarnetProcessingCenterDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN PROCESSINGCENTER_PKG.DuplicateCarnet( :P_USERID, :P_HEADERID :P_CURSOR ); END;`, { P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NUMBER }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async CloseCarnet(body: CarnetProcessingCenterDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN PROCESSINGCENTER_PKG.CloseCarnet( :P_USERID, :P_HEADERID :P_CURSOR ); END;`, { P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NUMBER }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, // 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } // [ CARNETCONTROLCENTER_PKG ] async GetHolderstoEdit(body: GetCarnetControlCenterDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN CARNETCONTROLCENTER_PKG.GetHolderstoEdit( :P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR ); END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async GetGoodsDetailstoEdit(body: GetCarnetControlCenterDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN CARNETCONTROLCENTER_PKG.GetGoodsDetailstoEdit( :P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR ); END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async GetCountryDetailstoEdit(body: GetCarnetControlCenterDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN CARNETCONTROLCENTER_PKG.GetCountryDetailstoEdit( :P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR ); END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } async GetShipPaymentDetailstoEdit(body: GetCarnetControlCenterDTO) { let connection; try { connection = await this.oracleDBService.getConnection(); const result = await connection.execute( `BEGIN CARNETCONTROLCENTER_PKG.GetShipPaymentDetailstoEdit( :P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR ); END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); 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."); } return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } }