updated login api according to doc

This commit is contained in:
Kallesh B S 2025-03-17 11:05:03 +05:30
parent df898db480
commit 813951de43
3 changed files with 129 additions and 68 deletions

View File

@ -20,7 +20,7 @@ export class AuthService {
const result = await connection.execute( const result = await connection.execute(
`BEGIN `BEGIN
USERLOGIN_PKG.ValidateUser(:p_emailaddr,:p_password,:p_login_cursor,:p_carnet_count_cur); USERLOGIN_PKG.ValidateUser(:p_emailaddr,:p_password,:p_login_cursor);
END;`, END;`,
{ {
p_emailaddr: { p_emailaddr: {
@ -34,10 +34,6 @@ export class AuthService {
p_login_cursor: { p_login_cursor: {
type: oracledb.CURSOR, type: oracledb.CURSOR,
dir: oracledb.BIND_OUT dir: oracledb.BIND_OUT
},
p_carnet_count_cur: {
type: oracledb.CURSOR,
dir: oracledb.BIND_OUT
} }
}, },
{ {
@ -62,63 +58,68 @@ export class AuthService {
throw new Error('No cursor returned from the stored procedure'); throw new Error('No cursor returned from the stored procedure');
} }
if (result.outBinds && result.outBinds.p_carnet_count_cur) { // if (result.outBinds && result.outBinds.p_carnet_count_cur) {
const cursor = result.outBinds.p_carnet_count_cur; // The OUT cursor // const cursor = result.outBinds.p_carnet_count_cur; // The OUT cursor
let rowsBatch; // let rowsBatch;
do { // do {
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time // rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
crows = crows.concat(rowsBatch); // Append fetched rows to the main array // crows = crows.concat(rowsBatch); // Append fetched rows to the main array
} while (rowsBatch.length > 0); // } while (rowsBatch.length > 0);
console.log('Rows fetched:', crows); // console.log('Rows fetched:', crows);
// Close the cursor after you're done // // Close the cursor after you're done
await cursor.close(); // await cursor.close();
} else { // } else {
throw new Error('No cursor returned from the stored procedure'); // throw new Error('No cursor returned from the stored procedure');
// }
// crows = crows.map(obj => {
// // Create a new object to hold the modified keys
// let newObj = {};
// // Iterate over the keys of the current object
// for (let key in obj) {
// // Replace spaces with underscores in the key
// let newKey = key.replace(/ /g, "_");
// newObj[newKey] = obj[key];
// }
// return newObj;
// });
// crows = crows.reduce((acc, curr) => {
// // Find if the current item already exists in the accumulator
// let existing = acc.find(item => item["Service_Provider_Name"] === curr["Service_Provider_Name"] && item.SPID === curr.SPID);
// if (existing) {
// // If it exists, push the current "cs" and "c c" values into the arrays
// existing.CARNETSTATUS.push(curr.CARNETSTATUS);
// existing["Carnet_Count"].push(curr["Carnet_Count"]);
// } else {
// // If it doesn't exist, create a new entry
// acc.push({
// "Service_Provider_Name": curr["Service_Provider_Name"],
// SPID: curr.SPID,
// CARNETSTATUS: [curr.CARNETSTATUS],
// "Carnet_Count": [curr["Carnet_Count"]]
// });
// }
// return acc;
// }, []);
// if(!crows[0].SPID){
// return {error:"Invalid username or password"}
// }
// return {rows,chartResult:crows};
if(rows[0]["ERRORMESG"]){
return {error:"Invalid username or password!"}
} }
return {msg:"Logged in successfully"}
crows = crows.map(obj => {
// Create a new object to hold the modified keys
let newObj = {};
// Iterate over the keys of the current object
for (let key in obj) {
// Replace spaces with underscores in the key
let newKey = key.replace(/ /g, "_");
newObj[newKey] = obj[key];
}
return newObj;
});
crows = crows.reduce((acc, curr) => {
// Find if the current item already exists in the accumulator
let existing = acc.find(item => item["Service_Provider_Name"] === curr["Service_Provider_Name"] && item.SPID === curr.SPID);
if (existing) {
// If it exists, push the current "cs" and "c c" values into the arrays
existing.CARNETSTATUS.push(curr.CARNETSTATUS);
existing["Carnet_Count"].push(curr["Carnet_Count"]);
} else {
// If it doesn't exist, create a new entry
acc.push({
"Service_Provider_Name": curr["Service_Provider_Name"],
SPID: curr.SPID,
CARNETSTATUS: [curr.CARNETSTATUS],
"Carnet_Count": [curr["Carnet_Count"]]
});
}
return acc;
}, []);
if(!crows[0].SPID){
return {error:"Invalid username or password"}
}
return {rows,chartResult:crows};
} catch (err) { } catch (err) {
console.error('Error fetching users: ', err.message); console.error('Error fetching users: ', err.message);

View File

@ -110,7 +110,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
if (result.outBinds && result.outBinds.p_contacts_cur) { if (result.outBinds && result.outBinds.p_contacts_cur) {
const cursor = result.outBinds.p_contacts_cur; const cursor = result.outBinds.p_contacts_cur;
@ -123,7 +123,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
if (result.outBinds && result.outBinds.p_sequence_cur) { if (result.outBinds && result.outBinds.p_sequence_cur) {
const cursor = result.outBinds.p_sequence_cur; const cursor = result.outBinds.p_sequence_cur;
@ -136,7 +136,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
if (result.outBinds && result.outBinds.p_fees_comm_cur) { if (result.outBinds && result.outBinds.p_fees_comm_cur) {
const cursor = result.outBinds.p_fees_comm_cur; const cursor = result.outBinds.p_fees_comm_cur;
@ -149,7 +149,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
if (result.outBinds && result.outBinds.p_bf_fee_cur) { if (result.outBinds && result.outBinds.p_bf_fee_cur) {
const cursor = result.outBinds.p_bf_fee_cur; const cursor = result.outBinds.p_bf_fee_cur;
@ -162,7 +162,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
if (result.outBinds && result.outBinds.p_cf_Fee_cur) { if (result.outBinds && result.outBinds.p_cf_Fee_cur) {
const cursor = result.outBinds.p_cf_Fee_cur; const cursor = result.outBinds.p_cf_Fee_cur;
@ -175,7 +175,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
if (result.outBinds && result.outBinds.p_cont_sheet_fee_cur) { if (result.outBinds && result.outBinds.p_cont_sheet_fee_cur) {
const cursor = result.outBinds.p_cont_sheet_fee_cur; const cursor = result.outBinds.p_cont_sheet_fee_cur;
@ -188,7 +188,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
if (result.outBinds && result.outBinds.p_ef_fee_cur) { if (result.outBinds && result.outBinds.p_ef_fee_cur) {
const cursor = result.outBinds.p_ef_fee_cur; const cursor = result.outBinds.p_ef_fee_cur;
@ -201,7 +201,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
if (result.outBinds && result.outBinds.p_security_deposit_cur) { if (result.outBinds && result.outBinds.p_security_deposit_cur) {
const cursor = result.outBinds.p_security_deposit_cur; const cursor = result.outBinds.p_security_deposit_cur;
@ -214,7 +214,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
if (result.outBinds && result.outBinds.p_param_cur) { if (result.outBinds && result.outBinds.p_param_cur) {
const cursor = result.outBinds.p_param_cur; const cursor = result.outBinds.p_param_cur;
@ -241,7 +241,7 @@ export class HomePageDataService {
await cursor.close(); await cursor.close();
} }
else { else {
throw new Error('No cursor returned from the stored procedure'); throw new Error('No cursor returned from the stored procedure');
} }
@ -266,4 +266,58 @@ export class HomePageDataService {
} finally { } } 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 { }
}
} }

View File

@ -22,6 +22,12 @@ export class OracleController {
return this.homePageDataService.GetHomePageData(id); return this.homePageDataService.GetHomePageData(id);
} }
@ApiTags('GetCarnetSummaryData - Oracle')
@Get('/GetCarnetSummaryData/:id')
GetCarnetSummaryData(@Param('id') id: string) {
return this.homePageDataService.GetCarnetSummaryData(id);
}
// Regions // Regions
@ApiTags('Regions - Oracle') @ApiTags('Regions - Oracle')