338 lines
13 KiB
TypeScript
338 lines
13 KiB
TypeScript
import { Injectable, Logger } from "@nestjs/common";
|
|
import { OracleDBService } from "src/db/db.service";
|
|
import { CLIENTLOCADDRESSTABLE_ROW_DTO, CONTACTSTABLE_ROW_DTO, COUNTRYTABLE_DTO, COUNTRYTABLE_ROW_DTO, GLTABLE_DTO, GLTABLE_ITEMNO_OPTIONAL_DTO, GLTABLE_ROW_ADD_DTO, GLTABLE_ROW_DTO } from "src/dto/property.dto";
|
|
import { InternalServerException } from "src/exceptions/internalServerError.exception";
|
|
import { closeOracleDbConnection, handleError } from "src/utils/helper";
|
|
|
|
@Injectable()
|
|
export class OracleService {
|
|
private readonly logger = new Logger(OracleService.name);
|
|
|
|
constructor(private readonly oracleDBService: OracleDBService) { }
|
|
|
|
async get_GL_TABLE_OPTIONAL_ITEMNO_INSTANCE(finalBody: any) {
|
|
|
|
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }
|
|
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }
|
|
|
|
let connection;
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const GLTABLE = await connection.getDbObjectClass('CARNETSYS.GLTABLE');
|
|
|
|
if (typeof GLTABLE !== 'function') {
|
|
throw new InternalServerException('GLTABLE is not a constructor');
|
|
}
|
|
|
|
async function createGLArrayInstance(
|
|
ITEMDESCRIPTION, ITEMVALUE, NOOFPIECES,
|
|
ITEMWEIGHT, ITEMWEIGHTUOM, GOODSORIGINCOUNTRY,
|
|
) {
|
|
const result = await connection.execute(
|
|
`SELECT CARNETSYS.GLARRAY(
|
|
:ITEMDESCRIPTION, :ITEMVALUE, :NOOFPIECES,
|
|
:ITEMWEIGHT, :ITEMWEIGHTUOM, :GOODSORIGINCOUNTRY
|
|
) FROM dual`,
|
|
{
|
|
ITEMDESCRIPTION, ITEMVALUE, NOOFPIECES,
|
|
ITEMWEIGHT, ITEMWEIGHTUOM, GOODSORIGINCOUNTRY,
|
|
}
|
|
);
|
|
return result.rows[0][0];
|
|
}
|
|
|
|
const GLTABLE_ARRAY: GLTABLE_ITEMNO_OPTIONAL_DTO = {
|
|
P_GLTABLE: await Promise.all(
|
|
(finalBody.P_GLTABLE ?? []).map(async (x: GLTABLE_ROW_ADD_DTO) => {
|
|
return await createGLArrayInstance(
|
|
x.ITEMDESCRIPTION, x.ITEMVALUE, x.NOOFPIECES,
|
|
x.ITEMWEIGHT, x.ITEMWEIGHTUOM, x.GOODSORIGINCOUNTRY,
|
|
);
|
|
})
|
|
)
|
|
};
|
|
|
|
const GLTABLE_INSTANCE = new GLTABLE(GLTABLE_ARRAY.P_GLTABLE ?? []);
|
|
|
|
return GLTABLE_INSTANCE;
|
|
|
|
} catch (error) {
|
|
throw new Error("Error occured completing this process")
|
|
} finally {
|
|
await closeOracleDbConnection(connection, OracleService.name)
|
|
}
|
|
}
|
|
|
|
async get_GL_TABLE_INSTANCE(finalBody: any) {
|
|
|
|
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }
|
|
// P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }
|
|
|
|
let connection;
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
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,
|
|
}
|
|
);
|
|
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 ?? []);
|
|
|
|
return GLTABLE_INSTANCE;
|
|
|
|
} catch (error) {
|
|
throw new Error("Error occured completing this process")
|
|
} finally {
|
|
await closeOracleDbConnection(connection, OracleService.name)
|
|
}
|
|
}
|
|
|
|
async get_COUNTRY_TABLE_INSTANCE(finalBody: any) {
|
|
|
|
// P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: 'CARNETSYS.CARNETCOUNTRYTABLE' }
|
|
// P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }
|
|
|
|
let connection;
|
|
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
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,
|
|
},
|
|
);
|
|
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 ?? []);
|
|
|
|
return COUNTRYTABLE_INSTANCE;
|
|
|
|
} catch (error) {
|
|
throw new Error("Error occured completing this process")
|
|
} finally {
|
|
await closeOracleDbConnection(connection, OracleService.name)
|
|
}
|
|
}
|
|
|
|
async get_CONTACTS_TABLE_INSTANCE(finalBody: any) {
|
|
|
|
// P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: 'CARNETSYS.CONTACTSTABLE' }
|
|
|
|
// P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }
|
|
// this is working fine for CreateCientContact
|
|
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const CONTACTSTABLE = await connection.getDbObjectClass('CARNETSYS.CONTACTSTABLE');
|
|
|
|
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] ?? [];
|
|
}
|
|
|
|
const CONTACTSARRAY = finalBody.P_CONTACTSTABLE
|
|
? await Promise.all(
|
|
finalBody.P_CONTACTSTABLE.map(async (x: CONTACTSTABLE_ROW_DTO) => {
|
|
return await CREATECONTACTSTABLE_INSTANCE(
|
|
connection,
|
|
x.P_FIRSTNAME,
|
|
x.P_LASTNAME,
|
|
x.P_MIDDLEINITIAL,
|
|
x.P_TITLE,
|
|
x.P_EMAILADDRESS,
|
|
x.P_PHONENO,
|
|
x.P_MOBILENO,
|
|
x?.P_FAXNO,
|
|
);
|
|
}),
|
|
)
|
|
: [];
|
|
|
|
const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE(CONTACTSARRAY);
|
|
|
|
return CONTACTSTABLE_INSTANCE;
|
|
|
|
} catch (error) {
|
|
throw new Error("Error occured completing this process")
|
|
} finally {
|
|
await closeOracleDbConnection(connection, OracleService.name)
|
|
}
|
|
}
|
|
|
|
async get_CONTACTS_TABLE_INSTANCEX(finalBody: any) {
|
|
|
|
// P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: 'CARNETSYS.CONTACTSTABLE' }
|
|
|
|
// P_CONTACTSTABLE: { val: CONTACTSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }
|
|
// this is working fine for CreateCientContact
|
|
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const CONTACTSROW = await connection.getDbObjectClass('C##CARNETSYS.CONTACTSROW');
|
|
const CONTACTSARRAY = await connection.getDbObjectClass('C##CARNETSYS.CONTACTSARRAY');
|
|
const CONTACTSTABLE = await connection.getDbObjectClass('C##CARNETSYS.CONTACTSTABLE');
|
|
|
|
const contactRows = finalBody.P_CONTACTSTABLE?.map((x: CONTACTSTABLE_ROW_DTO) => {
|
|
return new CONTACTSROW({
|
|
FIRSTNAME: x.P_FIRSTNAME,
|
|
LASTNAME: x.P_LASTNAME,
|
|
MIDDLEINITIAL: x.P_MIDDLEINITIAL,
|
|
TITLE: x.P_TITLE,
|
|
EMAILADDRESS: x.P_EMAILADDRESS,
|
|
PHONENO: x.P_PHONENO,
|
|
MOBILENO: x.P_MOBILENO,
|
|
FAXNO: x.P_FAXNO,
|
|
});
|
|
}) ?? [];
|
|
|
|
const contactsArrayInstance = new CONTACTSARRAY(contactRows);
|
|
const CONTACTSTABLE_INSTANCE = new CONTACTSTABLE({ CONTACTS: contactsArrayInstance });
|
|
|
|
return CONTACTSTABLE_INSTANCE;
|
|
|
|
} catch (error) {
|
|
throw new Error("Error occured completing this process")
|
|
} finally {
|
|
await closeOracleDbConnection(connection, OracleService.name)
|
|
}
|
|
}
|
|
|
|
async get_CLIENTLOCADDRESS_TABLE_INSTANCE(finalBody: any) {
|
|
|
|
// P_CLIENTLOCADDRESSTABLE: { val: CLIENTLOCADDRESSTABLE_INSTANCE, type: 'CARNETSYS.CLIENTLOCADDRESSTABLE' }
|
|
// P_CLIENTLOCADDRESSTABLE: { val: CLIENTLOCADDRESSTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }
|
|
|
|
let connection;
|
|
try {
|
|
connection = await this.oracleDBService.getConnection();
|
|
|
|
const CLIENTLOCADDRESSTABLE = await connection.getDbObjectClass('CARNETSYS.CLIENTLOCADDRESSTABLE');
|
|
|
|
if (typeof CLIENTLOCADDRESSTABLE !== 'function') {
|
|
throw new Error('CLIENTLOCADDRESSTABLE is not a constructor');
|
|
}
|
|
|
|
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 CLIENTLOCADDRESSARRAY = finalBody.P_CLIENTLOCADDRESSTABLE
|
|
? await Promise.all(
|
|
finalBody.P_CLIENTLOCADDRESSTABLE.map(
|
|
async (x: CLIENTLOCADDRESSTABLE_ROW_DTO) => {
|
|
return await CREATECLIENTLOCADDRESSTABLE_INSTANCE(
|
|
connection,
|
|
x.P_NAMEOF,
|
|
x.P_ADDRESS1,
|
|
x.P_ADDRESS2,
|
|
x.P_CITY,
|
|
x.P_STATE,
|
|
x.P_ZIP,
|
|
x.P_COUNTRY,
|
|
);
|
|
},
|
|
),
|
|
)
|
|
: [];
|
|
|
|
const CLIENTLOCADDRESSTABLE_INSTANCE = new CLIENTLOCADDRESSTABLE(CLIENTLOCADDRESSARRAY);
|
|
|
|
return CLIENTLOCADDRESSTABLE_INSTANCE;
|
|
|
|
} catch (error) {
|
|
throw new Error("Error occured completing this process")
|
|
} finally {
|
|
await closeOracleDbConnection(connection, OracleService.name)
|
|
}
|
|
}
|
|
} |