BE/src/oracle/homePageData.service.ts
2025-03-17 11:05:03 +05:30

323 lines
10 KiB
TypeScript

import { Injectable } from "@nestjs/common";
import { OracleDBService } from "src/db/db.service";
import * as oracledb from 'oracledb'
@Injectable()
export class HomePageDataService {
constructor(private readonly oracleDBService: OracleDBService) { }
async GetHomePageData(P_spid: number) {
let connection;
let p_basic_details = [];
let p_contacts = []
let p_sequence = [];
let p_fees_comm = [];
let p_bf_fee = [];
let p_cf_Fee = [];
let p_cont_sheet_fee = [];
let p_ef_fee = [];
let p_security_deposit = [];
let p_param = [];
let p_region = [];
try {
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
USERLOGIN_PKG.GetHomePageData(
:P_spid,
:p_basic_details_cur,
:p_contacts_cur,
:p_sequence_cur,
:p_fees_comm_cur,
:p_bf_fee_cur,
:p_cf_Fee_cur,
:p_cont_sheet_fee_cur,
:p_ef_fee_cur,
:p_security_deposit_cur,
:p_param_cur,
:p_region_cur
);
END;`,
{
P_spid: {
val: P_spid,
type: oracledb.DB_TYPE_NUMBER,
},
p_basic_details_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_contacts_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_sequence_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_fees_comm_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_bf_fee_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_cf_Fee_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_cont_sheet_fee_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_ef_fee_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_security_deposit_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_param_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
p_region_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
},
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
if (result.outBinds && result.outBinds.p_basic_details_cur) {
const cursor = result.outBinds.p_basic_details_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_basic_details = p_basic_details.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_contacts_cur) {
const cursor = result.outBinds.p_contacts_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_contacts = p_contacts.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_sequence_cur) {
const cursor = result.outBinds.p_sequence_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_sequence = p_sequence.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_fees_comm_cur) {
const cursor = result.outBinds.p_fees_comm_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_fees_comm = p_fees_comm.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_bf_fee_cur) {
const cursor = result.outBinds.p_bf_fee_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_bf_fee = p_bf_fee.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_cf_Fee_cur) {
const cursor = result.outBinds.p_cf_Fee_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_cf_Fee = p_cf_Fee.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_cont_sheet_fee_cur) {
const cursor = result.outBinds.p_cont_sheet_fee_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_cont_sheet_fee = p_cont_sheet_fee.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_ef_fee_cur) {
const cursor = result.outBinds.p_ef_fee_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_ef_fee = p_ef_fee.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_security_deposit_cur) {
const cursor = result.outBinds.p_security_deposit_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_security_deposit = p_security_deposit.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_param_cur) {
const cursor = result.outBinds.p_param_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_param = p_param.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
if (result.outBinds && result.outBinds.p_region_cur) {
const cursor = result.outBinds.p_region_cur;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
p_region = p_region.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
}
else {
throw new Error('No cursor returned from the stored procedure');
}
return {
p_basic_details,
p_contacts,
p_sequence,
p_fees_comm,
p_bf_fee,
p_cf_Fee,
p_cont_sheet_fee,
p_ef_fee,
p_security_deposit,
p_param,
p_region,
};
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
async GetCarnetSummaryData(p_emailaddr: string) {
let connection;
let rows = [];
try {
connection = await this.oracleDBService.getConnection()
if (!connection) {
throw new Error('No DB Connected')
}
const result = await connection.execute(
`BEGIN
USERLOGIN_PKG.GetCarnetSummaryData(:p_emailaddr,:p_cursor);
END;`,
{
p_emailaddr: {
val: p_emailaddr,
type: oracledb.DB_TYPE_NVARCHAR,
},
p_cursor: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
}
},
{
outFormat: oracledb.OUT_FORMAT_OBJECT
}
);
if (result.outBinds && result.outBinds.p_cursor) {
const cursor = result.outBinds.p_cursor;
let rowsBatch;
do {
rowsBatch = await cursor.getRows(100);
rows = rows.concat(rowsBatch);
} while (rowsBatch.length > 0);
await cursor.close();
} else {
throw new Error('No cursor returned from the stored procedure');
}
return rows;
} catch (err) {
console.error('Error fetching users: ', err);
throw new Error('Error fetching users');
} finally { }
}
}