diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 6d7d929..ddadfff 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -19,6 +19,7 @@ export class AuthController { @Post('login') @HttpCode(200) async loginClient(@Body() body: AuthLoginDTO, @Res({ passthrough: true }) res: Response, @Req() req: Request) { + let k: any = await this.authService.loginUser(body.P_EMAILADDR.toLowerCase(), body.P_PASSWORD, req); if (k.access_token) { diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index c349775..a3596aa 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -151,14 +151,12 @@ export class AuthService { // Validate the response shape if (!data?.keys || !Array.isArray(data.keys)) { - console.log("Invalid JWKS response"); throw new UnauthorizedException('Authentication failed'); } // Find the key with the matching kid const key = data.keys.find((k) => k.kid === kid); if (!key) { - console.log("Authentication failed: Key not found"); throw new UnauthorizedException('Authentication failed'); } @@ -174,7 +172,6 @@ export class AuthService { // Optionally log error details for debugging console.error('Failed to retrieve or process JWKS:', error); // Wrap other errors as InternalServerException - console.log('Failed to retrieve public key'); throw new InternalServerErrorException(); } } @@ -192,8 +189,6 @@ export class AuthService { return { active: Array.isArray(sessionData) && sessionData.length > 0 }; } catch (error: any) { - console.log("Error in introspectToken:", error.message || error); - if (error instanceof UnauthorizedException) { throw error; } @@ -224,7 +219,6 @@ export class AuthService { } catch (error) { if (error instanceof UnauthorizedException) throw error - console.log("Error while getting User session....."); throw new InternalServerErrorException() } } @@ -243,7 +237,6 @@ export class AuthService { const introspection = await this.introspectToken(token); if (!introspection.active) { - console.log("Introspect failed for token"); throw new UnauthorizedException("Authentication Failed") } @@ -266,9 +259,35 @@ export class AuthService { try { const userSession = await this.getUserSession(username) - + + const emailVerifyResponse: any = await this.userMaintenanceService.ValidateEmail({ P_EMAILADDR: username }) + + if (Array.isArray(emailVerifyResponse) && emailVerifyResponse[0].ERRORMESG) { + throw new BadRequestException(); + } + + let ROLE = ""; + + if (Array.isArray(emailVerifyResponse) && !emailVerifyResponse[0].ERRORMESG) { + switch (emailVerifyResponse[0].SOURCE) { + case "USCIB": ROLE = 'ua'; break; + case "SP": ROLE = 'sa'; break; + case "CLIENT": ROLE = 'ca'; break; + } + } + + // if (ROLE === 'ua' && req.headers.origin !== 'https://policy.alphaomegainfosys.com') { + // throw new BadRequestException("Invalid username or password") + // } + // else if (ROLE === 'sa' && req.headers.origin !== 'https://sp.alphaomegainfosys.com') { + // throw new BadRequestException("Invalid username or password") + // } + // else if (ROLE === 'ca' && req.headers.origin !== 'https://client.alphaomegainfosys.com') { + // throw new BadRequestException("Invalid username or password") + // } + if (access_token && refresh_token && userSession.length > 0) { - + const getSub: any = jwt.decode(refresh_token, { complete: true }) const user: any = await this.getUserDetailsById(getSub?.payload.sub) @@ -292,8 +311,6 @@ export class AuthService { return k; } catch (error) { - console.log("error while logging : ", error.message); - throw new BadRequestException('Invalid username or password'); } } @@ -314,7 +331,6 @@ export class AuthService { const response = await axios.request(options); if (response.status !== 200 || !Array.isArray(response.data)) { - console.log("failed to retrieve user-id...."); throw new UnauthorizedException("Authentication failed") } @@ -326,7 +342,6 @@ export class AuthService { } } catch (error) { - console.log("Error in getUserIdByEmail ..........."); if (error instanceof UnauthorizedException) { throw error } @@ -353,9 +368,6 @@ export class AuthService { return userResponse.data; } catch (error) { - console.log(error.message); - - console.log("Error in getUserDetailsById ..........."); if (error instanceof UnauthorizedException) { throw error; } @@ -377,9 +389,6 @@ export class AuthService { }); if (userResponse.status !== 200 || !Array.isArray(userResponse.data)) { - console.log("userResponse : ", userResponse); - console.log("userResponse status : ", userResponse.status); - throw new UnauthorizedException("Authentication failed"); } @@ -406,9 +415,6 @@ export class AuthService { }; } catch (error) { - console.log(error.message); - - console.log("Error in getUserDetailsByEmail ..........."); if (error instanceof UnauthorizedException) { throw error; } @@ -454,9 +460,6 @@ export class AuthService { try { const { data } = await axios.request(options2); - - console.log("forgot password status API request", data.status); - const forgotPasswordStatus = await this.updateForgotPassword(userDetails) if (!forgotPasswordStatus) { @@ -466,8 +469,6 @@ export class AuthService { return { statusCode: 200, message: 'password reset successfull' } } catch (error) { // console.error(error); - console.log(error.message); - throw new InternalServerErrorException() } @@ -487,7 +488,6 @@ export class AuthService { }); if (!data.access_token) { - console.log("failed to retrieve admin access token....."); throw new UnauthorizedException("Authentication failed") } @@ -495,7 +495,6 @@ export class AuthService { } catch (error) { if (error instanceof UnauthorizedException) throw error - console.log("Error in getAdminAccessToken"); throw new InternalServerErrorException(); } } @@ -567,30 +566,20 @@ export class AuthService { if (!ROLE) { - console.log("ERROR while giving access : "); throw new InternalServerErrorException(); } const res = await this.assignRoleToUser(uid, ROLE); - - console.log("Assigning Role sussessfully "); - - console.log(res); - return { statusCode: 201, message: 'User registered successfully' }; } } catch (error) { - console.log(error.message); - if (error.message === "Request failed with status code 409") { throw new ConflictException("User already exist"); } else if (error instanceof BadRequestException) { - console.log("ERROR while registering : ", error.message); return error; } - console.log("ERROR while giving access : ", error.message); throw new InternalServerErrorException('Failed to create user'); } } @@ -612,7 +601,6 @@ export class AuthService { }); if (response.status >= 200 && response.status < 300) { - console.log(`✅ Role "${roleName}" successfully assigned to user ${userId}.`); return { message: "Successfully assigned to user" }; } else { console.error(`❌ Failed to assign role. Status: ${response.status}, Data:`, response.data); @@ -724,9 +712,6 @@ export class AuthService { const refreshToken = req.cookies['refresh_token']; if (!refreshToken) { - - console.log("refesh token not present"); - throw new UnauthorizedException('Authentication failed'); } @@ -754,7 +739,6 @@ export class AuthService { } else { console.error('🔴 Unexpected error:', error.message); } - console.log("Error while refreshing tokens : ", error.message); throw new UnauthorizedException('Authentication failed'); } } @@ -783,18 +767,13 @@ export class AuthService { else { token = this.REGISTER_SIGN_JWT.sign({ email: payload.P_TO }); } - console.log("Register token : ", token); - if (!token) { - console.log("Register Token Generation failed"); throw new InternalServerErrorException(); } return token; } catch (error) { - console.log(error.message); - throw new InternalServerErrorException("Register Token Generation failed") } } @@ -826,17 +805,12 @@ export class AuthService { const userResponse = await axios.request(options2); if (userResponse.status !== 204) { - console.log("Error updating forgot-password : "); throw new InternalServerErrorException(); } return true; } catch (error) { - - console.log("Error updating forgot password"); - console.log("Error : ", error.message); - return false; } } @@ -872,7 +846,6 @@ export class AuthService { } async sendMail(body: SendMailDTO) { - console.log("mail body : ", body); let token: string; let ROLE: string = ""; let uuid: string | undefined = undefined; @@ -905,8 +878,6 @@ export class AuthService { try { await this.mailService.sendMail({ ...mailTemplate }); - console.log('Email sent successfully'); - if (body.P_MAIL_TYPE === MailTypeDTO.FORGOT_PASSWORD) { let forgotPasswordStatus = await this.updateForgotPassword(userDetails, uuid); diff --git a/src/db/db.service.ts b/src/db/db.service.ts index e24dcea..3ce3634 100644 --- a/src/db/db.service.ts +++ b/src/db/db.service.ts @@ -90,7 +90,6 @@ export class MssqlDBService { await this.pool.connect(); this.poolConnected = true; - console.log('Database connection pool initialized.'); } return this.pool; } catch (error) { diff --git a/src/guards/jwt-auth.guard.ts b/src/guards/jwt-auth.guard.ts index b6ee3b0..066eca6 100644 --- a/src/guards/jwt-auth.guard.ts +++ b/src/guards/jwt-auth.guard.ts @@ -21,16 +21,11 @@ export class JwtAuthGuard implements CanActivate { const token = request.cookies?.access_token; const body = request.body; - - console.log("from JWT guard body : ", body); - - if (body?.P_MAIL_TYPE && body?.P_MAIL_TYPE === MailTypeDTO.FORGOT_PASSWORD) { return true; } if (!token) { - console.log("No token found from Request"); throw new UnauthorizedException('Authentication failed'); } try { diff --git a/src/guards/register.guard.ts b/src/guards/register.guard.ts index 3b762be..74d6a16 100644 --- a/src/guards/register.guard.ts +++ b/src/guards/register.guard.ts @@ -30,8 +30,6 @@ export class RegisterGuard implements CanActivate { request['user'] = payload; return true; } catch (err) { - console.log("Error in register guard : ", err.message); - throw new UnauthorizedException("Invalid Register Token"); } } diff --git a/src/guards/roles.guard.ts b/src/guards/roles.guard.ts index a2e4638..cd86e12 100644 --- a/src/guards/roles.guard.ts +++ b/src/guards/roles.guard.ts @@ -26,9 +26,6 @@ export class RolesGuard implements CanActivate { const token = request.cookies?.access_token; // Token is stored as HttpOnly cookie const body = request.body; - - console.log("from JWT guard body : ", body); - if (body?.P_MAIL_TYPE && body?.P_MAIL_TYPE === MailTypeDTO.FORGOT_PASSWORD) { return true; } @@ -49,8 +46,6 @@ export class RolesGuard implements CanActivate { return true; } catch (err: any) { - console.log("from roles guard : ", err.message); - throw new UnauthorizedException('Authentication Failed'); } } diff --git a/src/interceptors/logout.interceptor.ts b/src/interceptors/logout.interceptor.ts index f471bb7..2f4219c 100644 --- a/src/interceptors/logout.interceptor.ts +++ b/src/interceptors/logout.interceptor.ts @@ -19,10 +19,6 @@ export class LogoutInterceptor implements NestInterceptor { // Send a custom 200 response when refresh token is missing response.clearCookie('access_token'); response.clearCookie('refresh_token'); - - console.log("No tokens found so logging-out"); - - response.status(200).json({ statusCode: 200, message: 'Logged-Out successfully', diff --git a/src/mssql/param-table/param-table.service.ts b/src/mssql/param-table/param-table.service.ts index 3cea2e9..b8e968f 100644 --- a/src/mssql/param-table/param-table.service.ts +++ b/src/mssql/param-table/param-table.service.ts @@ -57,6 +57,10 @@ export class ParamTableService { } async CREATEPARAMRECORD(body: CreateParamRecordDTO) { + + console.log("rbody : ", body); + + let connection: mssql.ConnectionPool; try { connection = await this.mssqlDBService.getConnection(); diff --git a/src/oracle/carnet-application/carnet-application.service.ts b/src/oracle/carnet-application/carnet-application.service.ts index 6e5ffba..4a95ccb 100644 --- a/src/oracle/carnet-application/carnet-application.service.ts +++ b/src/oracle/carnet-application/carnet-application.service.ts @@ -73,104 +73,10 @@ export class CarnetApplicationService { try { connection = await this.oracleDBService.getConnection(); - // const res = await connection.execute(`SELECT CARNETSYS.GLARRAY(1, 'Description for itemno 1', 2500, 20, 12, 'LBS', 'US') FROM dual`); - - // return res; - - // const GLTABLE = await connection.getDbObjectClass('CARNETSYS.GLTABLE'); - - // if (typeof GLTABLE !== 'function') { - // throw new InternalServerException('GLTABLE is not a constructor'); - // } - - // async function createGLArrayInstance( - // ITEMNO, - // ITEMDESCRIPTION, - // ITEMVALUE, - // NOOFPIECES, - // ITEMWEIGHT, - // ITEMWEIGHTUOM, - // GOODSORIGINCOUNTRY, - // ) { - // const result = await connection.execute( - // `SELECT CARNETSYS.GLARRAY(:ITEMNO, :ITEMDESCRIPTION, :ITEMVALUE, :NOOFPIECES, :ITEMWEIGHT, :ITEMWEIGHTUOM, :GOODSORIGINCOUNTRY) FROM dual`, - // { - // ITEMNO, - // ITEMDESCRIPTION, - // ITEMVALUE, - // NOOFPIECES, - // ITEMWEIGHT, - // ITEMWEIGHTUOM, - // GOODSORIGINCOUNTRY, - // }, - // ); - // console.log(result.rows); - - // return result.rows[0][0]; - // } - - // const GLTABLE_ARRAY: GLTABLE_DTO = { - // P_GLTABLE: await Promise.all( - // (finalBody.P_GLTABLE ?? []).map(async (x: GLTABLE_ROW_DTO) => { - // return await createGLArrayInstance( - // x.ITEMNO, - // x.ITEMDESCRIPTION, - // x.ITEMVALUE, - // x.NOOFPIECES, - // x.ITEMWEIGHT, - // x.ITEMWEIGHTUOM, - // x.GOODSORIGINCOUNTRY, - // ); - // }) - // ) - // }; - - // const GLTABLE_INSTANCE = new GLTABLE(GLTABLE_ARRAY.P_GLTABLE ?? []); const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_INSTANCE(finalBody); - // const COUNTRYTABLE = await connection.getDbObjectClass('CARNETSYS.CARNETCOUNTRYTABLE'); - - // if (typeof COUNTRYTABLE !== 'function') { - // throw new Error('COUNTRYTABLE is not a constructor'); - // } - - // async function createCarnetCountryArrayInstance( - // P_VISISTTRANSITIND, - // COUNTRYCODE, - // NOOFTIMESENTLEAVE, - // ) { - // const result = await connection.execute( - // `SELECT CARNETSYS.CARNETCOUNTRYARRAY(:P_VISISTTRANSITIND, :COUNTRYCODE, :NOOFTIMESENTLEAVE) FROM dual`, - // { - // P_VISISTTRANSITIND, - // COUNTRYCODE, - // NOOFTIMESENTLEAVE, - // }, - // ); - // console.log(result.rows); - // return result.rows[0][0]; - // } - - // const COUNTRYTABLE_ARRAY: COUNTRYTABLE_DTO = { - // P_COUNTRYTABLE: await Promise.all( - // (finalBody.P_COUNTRYTABLE ?? []).map(async (x: COUNTRYTABLE_ROW_DTO) => { - // return await createCarnetCountryArrayInstance( - // x.P_VISISTTRANSITIND, - // x.COUNTRYCODE, - // x.NOOFTIMESENTLEAVE, - // ); - // }) - // ) - // }; - - - // const COUNTRYTABLE_INSTANCE = new COUNTRYTABLE(COUNTRYTABLE_ARRAY.P_COUNTRYTABLE ?? []); - const COUNTRYTABLE_INSTANCE = await this.oracleService.get_COUNTRY_TABLE_INSTANCE(finalBody); - - // return { aa:GLTABLE_ARRAY, ab:COUNTRYTABLE_ARRAY, a: GLTABLE_INSTANCE, b: COUNTRYTABLE_INSTANCE } - const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.SaveCarnetApplication( @@ -193,7 +99,6 @@ export class CarnetApplicationService { P_AUTHREP: { val: body.P_AUTHREP, type: oracledb.DB_TYPE_VARCHAR }, P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, P_USSETS: { val: body.P_USSETS, type: oracledb.DB_TYPE_NUMBER }, - // P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: 'CARNETSYS.CARNETCOUNTRYTABLE' }, P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, P_SHIPTOTYPE: { val: body.P_SHIPTOTYPE, type: oracledb.DB_TYPE_VARCHAR }, P_SHIPADDRID: { val: body.P_SHIPADDRID, type: oracledb.DB_TYPE_NUMBER }, @@ -207,7 +112,6 @@ export class CarnetApplicationService { P_REFNO: { val: body.P_REFNO, type: oracledb.DB_TYPE_VARCHAR }, P_NOTES: { val: body.P_NOTES, type: oracledb.DB_TYPE_VARCHAR }, P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, - // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); @@ -248,10 +152,9 @@ export class CarnetApplicationService { END;`, { P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, - P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, - P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, - // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + P_CURSOR: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); @@ -715,11 +618,14 @@ export class CarnetApplicationService { throw new InternalServerException("Incomplete data received from the database."); } - return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + + return fres.length > 0 ? fres[0] : []; + } catch (error) { - handleError(error, CarnetApplicationService.name) + handleError(error, CarnetApplicationService.name); } finally { - await closeOracleDbConnection(connection, CarnetApplicationService.name) + await closeOracleDbConnection(connection, CarnetApplicationService.name); } } diff --git a/src/oracle/oracle.service.ts b/src/oracle/oracle.service.ts index 9cc6fd8..eb53a72 100644 --- a/src/oracle/oracle.service.ts +++ b/src/oracle/oracle.service.ts @@ -40,8 +40,6 @@ export class OracleService { ITEMWEIGHT, ITEMWEIGHTUOM, GOODSORIGINCOUNTRY, } ); - console.log(result.rows); - return result.rows[0][0]; } @@ -94,7 +92,6 @@ export class OracleService { P_VISISTTRANSITIND, COUNTRYCODE, NOOFTIMESENTLEAVE, }, ); - console.log(result.rows); return result.rows[0][0]; }