2025-04-02 13:03:48 +05:30
|
|
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
2025-03-11 10:52:58 +05:30
|
|
|
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 = [];
|
2025-03-13 11:29:54 +05:30
|
|
|
let crows:any = [];
|
2025-03-11 10:52:58 +05:30
|
|
|
try {
|
|
|
|
|
connection = await this.oracleDBService.getConnection()
|
|
|
|
|
if (!connection) {
|
|
|
|
|
throw new Error('No DB Connected')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await connection.execute(
|
|
|
|
|
`BEGIN
|
2025-03-17 11:05:03 +05:30
|
|
|
USERLOGIN_PKG.ValidateUser(:p_emailaddr,:p_password,:p_login_cursor);
|
2025-03-11 10:52:58 +05:30
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
outFormat: oracledb.OUT_FORMAT_OBJECT
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (result.outBinds && result.outBinds.p_login_cursor) {
|
2025-04-02 13:03:48 +05:30
|
|
|
const cursor = result.outBinds.p_login_cursor;
|
2025-03-11 10:52:58 +05:30
|
|
|
let rowsBatch;
|
|
|
|
|
|
|
|
|
|
do {
|
2025-04-02 13:03:48 +05:30
|
|
|
rowsBatch = await cursor.getRows(100);
|
|
|
|
|
rows = rows.concat(rowsBatch);
|
2025-03-11 10:52:58 +05:30
|
|
|
} while (rowsBatch.length > 0);
|
|
|
|
|
|
|
|
|
|
await cursor.close();
|
|
|
|
|
} else {
|
2025-04-02 13:03:48 +05:30
|
|
|
return new BadRequestException({Error:"Error executing request try after some time!"});
|
2025-03-11 10:52:58 +05:30
|
|
|
}
|
|
|
|
|
|
2025-03-17 11:05:03 +05:30
|
|
|
if(rows[0]["ERRORMESG"]){
|
|
|
|
|
return {error:"Invalid username or password!"}
|
|
|
|
|
}
|
|
|
|
|
return {msg:"Logged in successfully"}
|
2025-03-11 10:52:58 +05:30
|
|
|
|
|
|
|
|
} catch (err) {
|
2025-03-13 12:42:31 +05:30
|
|
|
console.error('Error fetching users: ', err.message);
|
|
|
|
|
return {error:"Invalid username or password"}
|
2025-03-11 10:52:58 +05:30
|
|
|
} finally { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|