updated login api according to doc
This commit is contained in:
parent
df898db480
commit
813951de43
@ -20,7 +20,7 @@ export class AuthService {
|
||||
|
||||
const result = await connection.execute(
|
||||
`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;`,
|
||||
{
|
||||
p_emailaddr: {
|
||||
@ -34,10 +34,6 @@ export class AuthService {
|
||||
p_login_cursor: {
|
||||
type: oracledb.CURSOR,
|
||||
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');
|
||||
}
|
||||
|
||||
if (result.outBinds && result.outBinds.p_carnet_count_cur) {
|
||||
const cursor = result.outBinds.p_carnet_count_cur; // The OUT cursor
|
||||
let rowsBatch;
|
||||
// if (result.outBinds && result.outBinds.p_carnet_count_cur) {
|
||||
// const cursor = result.outBinds.p_carnet_count_cur; // The OUT cursor
|
||||
// let rowsBatch;
|
||||
|
||||
do {
|
||||
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
||||
crows = crows.concat(rowsBatch); // Append fetched rows to the main array
|
||||
} while (rowsBatch.length > 0);
|
||||
// do {
|
||||
// rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
||||
// crows = crows.concat(rowsBatch); // Append fetched rows to the main array
|
||||
// } while (rowsBatch.length > 0);
|
||||
|
||||
console.log('Rows fetched:', crows);
|
||||
// console.log('Rows fetched:', crows);
|
||||
|
||||
// Close the cursor after you're done
|
||||
await cursor.close();
|
||||
} else {
|
||||
throw new Error('No cursor returned from the stored procedure');
|
||||
// // Close the cursor after you're done
|
||||
// await cursor.close();
|
||||
// } else {
|
||||
// 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!"}
|
||||
}
|
||||
|
||||
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};
|
||||
return {msg:"Logged in successfully"}
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error fetching users: ', err.message);
|
||||
|
||||
@ -110,7 +110,7 @@ export class HomePageDataService {
|
||||
|
||||
|
||||
await cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.outBinds && result.outBinds.p_contacts_cur) {
|
||||
const cursor = result.outBinds.p_contacts_cur;
|
||||
@ -123,7 +123,7 @@ export class HomePageDataService {
|
||||
|
||||
|
||||
await cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.outBinds && result.outBinds.p_sequence_cur) {
|
||||
const cursor = result.outBinds.p_sequence_cur;
|
||||
@ -136,7 +136,7 @@ export class HomePageDataService {
|
||||
|
||||
|
||||
await cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.outBinds && result.outBinds.p_fees_comm_cur) {
|
||||
const cursor = result.outBinds.p_fees_comm_cur;
|
||||
@ -149,7 +149,7 @@ export class HomePageDataService {
|
||||
|
||||
|
||||
await cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.outBinds && result.outBinds.p_bf_fee_cur) {
|
||||
const cursor = result.outBinds.p_bf_fee_cur;
|
||||
@ -162,7 +162,7 @@ export class HomePageDataService {
|
||||
|
||||
|
||||
await cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.outBinds && result.outBinds.p_cf_Fee_cur) {
|
||||
const cursor = result.outBinds.p_cf_Fee_cur;
|
||||
@ -175,7 +175,7 @@ export class HomePageDataService {
|
||||
|
||||
|
||||
await cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.outBinds && 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();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.outBinds && result.outBinds.p_ef_fee_cur) {
|
||||
const cursor = result.outBinds.p_ef_fee_cur;
|
||||
@ -201,7 +201,7 @@ export class HomePageDataService {
|
||||
|
||||
|
||||
await cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.outBinds && result.outBinds.p_security_deposit_cur) {
|
||||
const cursor = result.outBinds.p_security_deposit_cur;
|
||||
@ -214,7 +214,7 @@ export class HomePageDataService {
|
||||
|
||||
|
||||
await cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (result.outBinds && result.outBinds.p_param_cur) {
|
||||
const cursor = result.outBinds.p_param_cur;
|
||||
@ -241,7 +241,7 @@ export class HomePageDataService {
|
||||
|
||||
await cursor.close();
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
throw new Error('No cursor returned from the stored procedure');
|
||||
}
|
||||
@ -266,4 +266,58 @@ export class HomePageDataService {
|
||||
} 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 { }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -22,6 +22,12 @@ export class OracleController {
|
||||
return this.homePageDataService.GetHomePageData(id);
|
||||
}
|
||||
|
||||
@ApiTags('GetCarnetSummaryData - Oracle')
|
||||
@Get('/GetCarnetSummaryData/:id')
|
||||
GetCarnetSummaryData(@Param('id') id: string) {
|
||||
return this.homePageDataService.GetCarnetSummaryData(id);
|
||||
}
|
||||
|
||||
// Regions
|
||||
|
||||
@ApiTags('Regions - Oracle')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user