diff --git a/src/oracle/user-maintenance/user-maintenance.controller.ts b/src/oracle/user-maintenance/user-maintenance.controller.ts index abb16f5..ff56b32 100644 --- a/src/oracle/user-maintenance/user-maintenance.controller.ts +++ b/src/oracle/user-maintenance/user-maintenance.controller.ts @@ -2,7 +2,7 @@ import { Body, Controller, Get, Param, Patch, Post, Query } from '@nestjs/common import { UserMaintenanceService } from './user-maintenance.service'; import { ApiTags } from '@nestjs/swagger'; import { CreateClientLoginsDTO, CreateSPLoginsDTO, CreateUSCIBLoginsDTO, SPID_CLIENTID_DTO, SPID_EMAIL_DTO } from '../../dto/user-maintenance/user-maintenance.dto'; -import { USERID_DTO } from 'src/dto/property.dto'; +import { EMAIL_DTO, USERID_DTO } from 'src/dto/property.dto'; import { SPID_DTO } from 'src/dto/sp/sp-property.dto'; @ApiTags('User Maintenance - Oracle') @@ -62,4 +62,11 @@ export class UserMaintenanceController { async CreateClientLogins(@Body() body: CreateClientLoginsDTO) { return await this.userMaintenanceService.CreateClientLogins(body); } + + // validate email + + @Get('ValidateEmail/:P_EMAILADDR') + async ValidateEmail(@Param() params: EMAIL_DTO) { + return await this.userMaintenanceService.ValidateEmail(params); + } } diff --git a/src/oracle/user-maintenance/user-maintenance.service.ts b/src/oracle/user-maintenance/user-maintenance.service.ts index cfb79d8..6ec6eaa 100644 --- a/src/oracle/user-maintenance/user-maintenance.service.ts +++ b/src/oracle/user-maintenance/user-maintenance.service.ts @@ -7,7 +7,7 @@ import { import { InternalServerException } from 'src/exceptions/internalServerError.exception'; import * as oracledb from 'oracledb'; import { BadRequestException } from 'src/exceptions/badRequest.exception'; -import { USERID_DTO } from 'src/dto/property.dto'; +import { EMAIL_DTO, USERID_DTO } from 'src/dto/property.dto'; import { closeOracleDbConnection, fetchCursor, handleError } from 'src/utils/helper'; import { SPID_DTO } from 'src/dto/sp/sp-property.dto'; @@ -380,6 +380,40 @@ export class UserMaintenanceService { await closeOracleDbConnection(connection, UserMaintenanceService.name) } } + + // validate email + + async ValidateEmail(body: EMAIL_DTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + userlogin_pkg.ValidateEmail( + :P_EMAILADDR, :P_CURSOR + ); + END;`, + { + P_EMAILADDR: { val: body.P_EMAILADDR, type: oracledb.DB_TYPE_NVARCHAR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + }, + { outFormat: oracledb.OUT_FORMAT_OBJECT } + ); + + 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."); + } + + return await fetchCursor(outBinds.P_CURSOR, UserMaintenanceService.name); + } catch (error) { + handleError(error, UserMaintenanceService.name) + } finally { + await closeOracleDbConnection(connection, UserMaintenanceService.name) + } + } }