2025-03-11 10:52:58 +05:30
|
|
|
import { Injectable } from '@nestjs/common';
|
|
|
|
|
import { OracleDBService } from 'src/db/db.service';
|
|
|
|
|
import { AuthLoginDTO } from './auth.dto';
|
|
|
|
|
import * as oracledb from 'oracledb'
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class AuthService {
|
|
|
|
|
|
|
|
|
|
constructor(private readonly oracleDBService: OracleDBService) { }
|
|
|
|
|
|
|
|
|
|
async login(body:AuthLoginDTO) {
|
|
|
|
|
let connection;
|
|
|
|
|
let rows = [];
|
|
|
|
|
let crows = [];
|
|
|
|
|
try {
|
|
|
|
|
connection = await this.oracleDBService.getConnection()
|
|
|
|
|
if (!connection) {
|
|
|
|
|
throw new Error('No DB Connected')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await connection.execute(
|
|
|
|
|
`BEGIN
|
|
|
|
|
USERLOGIN_PKG.ValidateUser(:p_emailaddr,:p_password,:p_login_cursor,:p_carnet_count_cur);
|
|
|
|
|
END;`,
|
|
|
|
|
{
|
|
|
|
|
p_emailaddr: {
|
|
|
|
|
val: body.p_emailaddr,
|
|
|
|
|
type: oracledb.DB_TYPE_NVARCHAR
|
|
|
|
|
},
|
|
|
|
|
p_password: {
|
|
|
|
|
val: body.p_password,
|
|
|
|
|
type: oracledb.DB_TYPE_NVARCHAR
|
|
|
|
|
},
|
|
|
|
|
p_login_cursor: {
|
|
|
|
|
type: oracledb.CURSOR,
|
|
|
|
|
dir: oracledb.BIND_OUT
|
|
|
|
|
},
|
|
|
|
|
p_carnet_count_cur: {
|
|
|
|
|
type: oracledb.CURSOR,
|
|
|
|
|
dir: oracledb.BIND_OUT
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (result.outBinds && result.outBinds.p_login_cursor) {
|
|
|
|
|
const cursor = result.outBinds.p_login_cursor; // The OUT cursor
|
|
|
|
|
let rowsBatch;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
|
|
|
|
rows = rows.concat(rowsBatch); // Append fetched rows to the main array
|
|
|
|
|
} while (rowsBatch.length > 0);
|
|
|
|
|
|
|
|
|
|
console.log('Rows fetched:', rows);
|
|
|
|
|
|
|
|
|
|
// Close the cursor after you're done
|
|
|
|
|
await cursor.close();
|
|
|
|
|
} else {
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
rowsBatch = await cursor.getRows(100); // Fetch 100 rows at a time
|
2025-03-11 15:53:25 +05:30
|
|
|
crows = crows.concat(rowsBatch); // Append fetched rows to the main array
|
2025-03-11 10:52:58 +05:30
|
|
|
} while (rowsBatch.length > 0);
|
|
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {rows,crows};
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Error fetching users: ', err);
|
|
|
|
|
throw new Error('Error fetching users');
|
|
|
|
|
} finally { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|