From 30814650a4495b99e844b3249069b9d8d39a73f1 Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Mon, 9 Jun 2025 10:55:50 +0530 Subject: [PATCH] login, client modified --- src/auth/auth.dto.ts | 4 +- src/auth/auth.service.ts | 10 +- src/dto/manage-clients/manage-clients.dto.ts | 6 + .../manage-clients.controller.ts | 21 ++- .../manage-clients/manage-clients.service.ts | 134 ++++++++++++++++++ 5 files changed, 167 insertions(+), 8 deletions(-) diff --git a/src/auth/auth.dto.ts b/src/auth/auth.dto.ts index 181584e..e557d41 100644 --- a/src/auth/auth.dto.ts +++ b/src/auth/auth.dto.ts @@ -4,9 +4,9 @@ import { IsString } from 'class-validator'; export class AuthLoginDTO { @ApiProperty({ required: true }) @IsString() - p_emailaddr: string; + P_EMAILADDR: string; @ApiProperty({ required: true }) @IsString() - p_password: string; + P_PASSWORD: string; } diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index aabcea9..75b11c8 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -18,15 +18,15 @@ export class AuthService { const result = await connection.execute( `BEGIN - USERLOGIN_PKG.ValidateUser(:p_emailaddr,:p_password,:p_login_cursor); + USERLOGIN_PKG.ValidateUser(:P_EMAILADDR,:P_PASSWORD,:p_login_cursor); END;`, { - p_emailaddr: { - val: body.p_emailaddr, + P_EMAILADDR: { + val: body.P_EMAILADDR, type: oracledb.DB_TYPE_NVARCHAR, }, - p_password: { - val: body.p_password, + P_PASSWORD: { + val: body.P_PASSWORD, type: oracledb.DB_TYPE_NVARCHAR, }, p_login_cursor: { diff --git a/src/dto/manage-clients/manage-clients.dto.ts b/src/dto/manage-clients/manage-clients.dto.ts index ea8ab16..fadc8b5 100644 --- a/src/dto/manage-clients/manage-clients.dto.ts +++ b/src/dto/manage-clients/manage-clients.dto.ts @@ -119,3 +119,9 @@ export class GetClientDTO extends IntersectionType( SPID_DTO, CLIENTID_DTO ) { } + +export class ClientContactControlsDTO extends IntersectionType( + GetClientDTO, + USERID_DTO +) { } + diff --git a/src/oracle/manage-clients/manage-clients.controller.ts b/src/oracle/manage-clients/manage-clients.controller.ts index f636c7d..3d11a29 100644 --- a/src/oracle/manage-clients/manage-clients.controller.ts +++ b/src/oracle/manage-clients/manage-clients.controller.ts @@ -1,8 +1,9 @@ -import { Body, Controller, Get, Param, Post, Put, Query } from '@nestjs/common'; +import { Body, Controller, Get, Param, Patch, Post, Put, Query } from '@nestjs/common'; import { ManageClientsService } from './manage-clients.service'; import { ApiTags } from '@nestjs/swagger'; import { + ClientContactControlsDTO, CreateClientContactsDTO, CreateClientDataDTO, CreateClientLocationsDTO, GetClientDTO, @@ -43,6 +44,24 @@ export class ManageClientsController { return this.manageClientsService.CreateClientContact(body); } + @ApiTags('Manage Clients - Oracle') + @Patch('SetDefaultClientContacts/:P_SPID/:P_CLIENTID/:P_USERID') + SetDefaultClientContacts(@Param() param: ClientContactControlsDTO) { + return this.manageClientsService.SetDefaultClientContacts(param); + } + + @ApiTags('Manage Clients - Oracle') + @Patch('InactivateClientContacts/:P_SPID/:P_CLIENTID/:P_USERID') + InactivateClientContacts(@Param() param: ClientContactControlsDTO) { + return this.manageClientsService.InactivateClientContacts(param); + } + + @ApiTags('Manage Clients - Oracle') + @Patch('ReactivateClientContacts/:P_SPID/:P_CLIENTID/:P_USERID') + ReactivateClientContacts(@Param() param: ClientContactControlsDTO) { + return this.manageClientsService.ReactivateClientContacts(param); + } + @ApiTags('Manage Clients - Oracle') @Post('CreateClientLocations') CreateClientLocation(@Body() body: CreateClientLocationsDTO) { diff --git a/src/oracle/manage-clients/manage-clients.service.ts b/src/oracle/manage-clients/manage-clients.service.ts index a374c2c..694d9f1 100644 --- a/src/oracle/manage-clients/manage-clients.service.ts +++ b/src/oracle/manage-clients/manage-clients.service.ts @@ -7,6 +7,7 @@ import { InternalServerException } from 'src/exceptions/internalServerError.exce import { closeOracleDbConnection, fetchCursor, handleError, setEmptyStringsToNull } from 'src/utils/helper'; import { + ClientContactControlsDTO, CreateClientContactsDTO, CreateClientDataDTO, CreateClientLocationsDTO, GetClientDTO, @@ -388,6 +389,139 @@ export class ManageClientsService { } } + SetDefaultClientContacts = async (body: ClientContactControlsDTO) => { + + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + MANAGEPREPARER_PKG.CreateClientContact( + :P_SPID, :P_CLIENTID, :P_USERID, :P_CURSOR + ); + END;`, + { + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTID: { val: body.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + }, + { outFormat: oracledb.OUT_FORMAT_OBJECT } + ); + + await connection.commit(); + + const outBinds = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); + } + + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Default contact added successfully", ...fres[0] }; + + } catch (error) { + handleError(error, ManageClientsService.name) + } finally { + await closeOracleDbConnection(connection, ManageClientsService.name) + } + } + + InactivateClientContacts = async (body: ClientContactControlsDTO) => { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + MANAGEPREPARER_PKG.CreateClientContact( + :P_SPID, :P_CLIENTID, :P_USERID, :P_CURSOR + ); + END;`, + { + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTID: { val: body.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + }, + { outFormat: oracledb.OUT_FORMAT_OBJECT } + ); + + await connection.commit(); + + const outBinds = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); + } + + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Contact inactivated successfully", ...fres[0] }; + + } catch (error) { + handleError(error, ManageClientsService.name) + } finally { + await closeOracleDbConnection(connection, ManageClientsService.name) + } + } + + ReactivateClientContacts = async (body: ClientContactControlsDTO) => { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + MANAGEPREPARER_PKG.CreateClientContact( + :P_SPID, :P_CLIENTID, :P_USERID, :P_CURSOR + ); + END;`, + { + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_CLIENTID: { val: body.P_CLIENTID, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + }, + { outFormat: oracledb.OUT_FORMAT_OBJECT } + ); + + await connection.commit(); + + const outBinds = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); + } + + const fres: any = await fetchCursor(outBinds.P_CURSOR, ManageClientsService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Contact reactivated successfully", ...fres[0] }; + + } catch (error) { + handleError(error, ManageClientsService.name) + } finally { + await closeOracleDbConnection(connection, ManageClientsService.name) + } + } + CreateClientLocation = async (body: CreateClientLocationsDTO) => { const newBody = { P_SPID: null,