resolved bug for array type mismatch and updated api

This commit is contained in:
Kallesh B S 2025-03-25 15:01:14 +05:30
parent 0227d9ced0
commit f1edfe48d2
2 changed files with 132 additions and 61 deletions

View File

@ -1,7 +1,7 @@
import { Injectable } from "@nestjs/common";
import { OracleDBService } from "src/db/db.service";
import * as oracledb from 'oracledb'
import { GetCarnetDetailsbyCarnetStatusDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO } from "./oracle.dto";
import { GetCarnetDetailsbyCarnetStatusDTO, p_countrytableDTO, p_gltableDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO } from "./oracle.dto";
@Injectable()
export class HomePageDataService {
@ -380,6 +380,47 @@ export class HomePageDataService {
async SaveCarnetApplication(body: SaveCarnetApplicationDTO) {
let newBody = {
"p_headerid": 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
}
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 = { ...newBody, ...reqBody };
let connection;
let rows = [];
try {
@ -389,146 +430,176 @@ export class HomePageDataService {
throw new Error('No DB Connected')
}
// 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');
const GLTABLE = await connection.getDbObjectClass('CARNETSYS.GLTABLE');
const CARNETCOUNTRYARRAY = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYARRAY');
const CARNETCOUNTRYTABLE = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYTABLE');
// Check if GLTABLE is a constructor
if (typeof GLTABLE !== 'function') {
throw new Error('GLTABLE is not a constructor');
}
if (typeof CARNETCOUNTRYTABLE !== 'function') {
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)
}):[];
const CARNETCOUNTRYTABLE_ARRAY = finalBody.p_countrytable ? finalBody.p_countrytable.map((x: p_countrytableDTO) => {
return new CARNETCOUNTRYARRAY(x.VisitTransitInd, x.CountryCode, x.NoOfTimesEntLeave)
}):[];
// Create an instance of GLTABLE
const GLTABLE_INSTANCE = new GLTABLE(GLTABLE_ARRAY);
const CARNETCOUNTRYTABLE_INSTANCE = new CARNETCOUNTRYTABLE(CARNETCOUNTRYTABLE_ARRAY);
// return { GLTABLE_INSTANCE,CARNETCOUNTRYTABLE_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_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,
val: finalBody.p_spid ? finalBody.p_spid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_clientid: {
val: body.p_spid,
val: finalBody.p_clientid ? finalBody.p_clientid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_locationid: {
val: body.p_spid,
val: finalBody.p_locationid ? finalBody.p_locationid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_userid: {
val: body.p_spid,
val: finalBody.p_userid ? finalBody.p_userid : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_headerid: {
val: body.p_spid,
val: finalBody.p_headerid ? finalBody.p_headerid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_applicationname: {
val: body.p_spid,
val: finalBody.p_applicationname ? finalBody.p_applicationname : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_holderid: {
val: body.p_spid,
val: finalBody.p_holderid ? finalBody.p_holderid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_commercialsampleflag: {
val: body.p_spid,
val: finalBody.p_commercialsampleflag ? finalBody.p_commercialsampleflag : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_profequipmentflag: {
val: body.p_spid,
val: finalBody.p_profequipmentflag ? finalBody.p_profequipmentflag : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_exhibitionsfairflag: {
val: body.p_spid,
val: finalBody.p_exhibitionsfairflag ? finalBody.p_exhibitionsfairflag : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_autoflag: {
val: body.p_spid,
val: finalBody.p_autoflag ? finalBody.p_autoflag : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_horseflag: {
val: body.p_spid,
val: finalBody.p_horseflag ? finalBody.p_horseflag : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_authrep: {
val: body.p_spid,
val: finalBody.p_authrep ? finalBody.p_authrep : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_gltable: {
val: body.p_spid,
val: GLTABLE_INSTANCE,
type: oracledb.DB_TYPE_OBJECT
},
p_ussets: {
val: body.p_spid,
val: finalBody.p_ussets ? finalBody.p_ussets : null,
type: oracledb.DB_TYPE_NUMBER
},
p_countrytable: {
val: body.p_spid,
val: CARNETCOUNTRYTABLE_INSTANCE,
type: oracledb.DB_TYPE_OBJECT
},
p_shiptotype: {
val: body.p_spid,
val: finalBody.p_shiptotype ? finalBody.p_shiptotype : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_shipaddrid: {
val: body.p_spid,
val: finalBody.p_shipaddrid ? finalBody.p_shipaddrid : null,
type: oracledb.DB_TYPE_NUMBER
},
p_formofsecurity: {
val: body.p_spid,
val: finalBody.p_formofsecurity ? finalBody.p_formofsecurity : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_insprotection: {
val: body.p_spid,
val: finalBody.p_insprotection ? finalBody.p_insprotection : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_ldiprotection: {
val: body.p_spid,
val: finalBody.p_ldiprotection ? finalBody.p_ldiprotection : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_deliverytype: {
val: body.p_spid,
val: finalBody.p_deliverytype ? finalBody.p_deliverytype : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_deliverymethod: {
val: body.p_spid,
val: finalBody.p_deliverymethod ? finalBody.p_deliverymethod : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_paymentmethod: {
val: body.p_spid,
val: finalBody.p_paymentmethod ? finalBody.p_paymentmethod : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_custcourierno: {
val: body.p_spid,
val: finalBody.p_custcourierno ? finalBody.p_custcourierno : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_refno: {
val: body.p_spid,
val: finalBody.p_refno ? finalBody.p_refno : null,
type: oracledb.DB_TYPE_NVARCHAR
},
p_notes: {
val: body.p_spid,
val: finalBody.p_notes ? finalBody.p_notes : null,
type: oracledb.DB_TYPE_NVARCHAR
},

View File

@ -866,31 +866,31 @@ export class SaveCarnetApplicationDTO {
@Length(0, 1, { message: "Property p_commercialsampleflag must be between 0 to 1 characters" })
@IsString()
@IsOptional()
p_commercialsampleflag?: number;
p_commercialsampleflag?: string;
@ApiProperty({ required: false })
@Length(0, 1, { message: "Property p_profequipmentflag must be between 0 to 1 characters" })
@IsString()
@IsOptional()
p_profequipmentflag?: number;
p_profequipmentflag?: string;
@ApiProperty({ required: false })
@Length(0, 1, { message: "Property p_exhibitionsfairflag must be between 0 to 1 characters" })
@IsString()
@IsOptional()
p_exhibitionsfairflag?: number;
p_exhibitionsfairflag?: string;
@ApiProperty({ required: false })
@Length(0, 1, { message: "Property p_autoflag must be between 0 to 1 characters" })
@IsString()
@IsOptional()
p_autoflag?: number;
p_autoflag?: string;
@ApiProperty({ required: false })
@Length(0, 1, { message: "Property p_horseflag must be between 0 to 1 characters" })
@IsString()
@IsOptional()
p_horseflag?: number;
p_horseflag?: string;
@ApiProperty({ required: false })
@Length(0, 200, { message: "Property p_authrep must be between 0 to 200 characters" })
@ -975,7 +975,7 @@ export class SaveCarnetApplicationDTO {
@Length(0, 20, { message: "Property p_custcourierno must be between 0 to 20 characters" })
@IsString()
@IsOptional()
p_custcourierno?: number;
p_custcourierno?: string;
@ApiProperty({ required: false })
@Length(0, 20, { message: "Property p_refno must be between 0 to 20 characters" })