From b9198acfe72471be8f9b9548a957bdae1e93ae64 Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Mon, 7 Apr 2025 11:36:24 +0530 Subject: [PATCH] added service to getSPAllContacts --- src/main.ts | 1 + .../sp-contacts/sp-contacts.controller.ts | 10 ++-- .../sp-contacts/sp-contacts.dto.ts | 2 + .../sp-contacts/sp-contacts.service.ts | 56 ++++++++++++++++++- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4401b97..3107714 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,6 +11,7 @@ import { SwaggerDocumentOptions } from '@nestjs/swagger'; async function bootstrap() { const app = await NestFactory.create(AppModule, { cors: { + // origin: 'https://dev.alphaomegainfosys.com/', origin: '*', methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', preflightContinue: false, diff --git a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.controller.ts b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.controller.ts index f339ec0..3a5474d 100644 --- a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.controller.ts +++ b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.controller.ts @@ -1,6 +1,7 @@ import { SpContactsService } from './sp-contacts.service'; import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common'; import { + getSPAllContactsDTO, getSPDefaultcontactDTO, inactivateSPContactDTO, InsertSPContactsDTO, @@ -43,8 +44,9 @@ export class SpContactsController { return this.spContactsService.getSPDefaultcontacts(body); } - // @Get('/GetAllSPcontacts') - // getSPcontacts() { - // return this.oarcleService.getSPcontacts(); - // } + @ApiTags('SPContacts - Oracle') + @Get('/GetSPAllContacts') + getSPAllContacts(@Query() body: getSPAllContactsDTO) { + return this.spContactsService.getSPDefaultcontacts(body); + } } diff --git a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto.ts b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto.ts index 90b1eab..fa3ed03 100644 --- a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto.ts +++ b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.dto.ts @@ -117,3 +117,5 @@ export class getSPDefaultcontactDTO { @IsDefined({ message: 'Property p_SPid is required' }) p_SPid: number; } + +export class getSPAllContactsDTO extends getSPDefaultcontactDTO{} diff --git a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts index 5b14ff2..b978689 100644 --- a/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts +++ b/src/oracle/uscib-managed-sp/sp-contacts/sp-contacts.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; import * as oracledb from 'oracledb'; import { + getSPAllContactsDTO, getSPDefaultcontactDTO, inactivateSPContactDTO, InsertSPContactsDTO, @@ -11,7 +12,7 @@ import { @Injectable() export class SpContactsService { - constructor(private readonly oracleDBService: OracleDBService) {} + constructor(private readonly oracleDBService: OracleDBService) { } async insertSPContacts(body: InsertSPContactsDTO) { let connection; @@ -357,4 +358,57 @@ export class SpContactsService { } } } + + async getSPAllContacts(body: getSPAllContactsDTO) { + + let connection; + let rows = []; + try { + connection = await this.oracleDBService.getConnection(); + if (!connection) { + throw new Error('No DB Connected'); + } + + const result = await connection.execute( + `BEGIN + USCIB_Managed_Pkg.GetSPAllContacts(:p_SPid,:p_cursor); + END;`, + { + p_SPid: { + val: body.p_SPid, + type: oracledb.DB_TYPE_NUMBER, + }, + p_cursor: { + type: oracledb.CURSOR, + dir: oracledb.BIND_OUT, + }, + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + if (result.outBinds && result.outBinds.p_cursor) { + const cursor = result.outBinds.p_cursor; + let rowsBatch; + + do { + rowsBatch = await cursor.getRows(100); + rows = rows.concat(rowsBatch); + } while (rowsBatch.length > 0); + + await cursor.close(); + } else { + throw new Error('No cursor returned from the stored procedure'); + } + + return rows; + } catch (err) { + if (err instanceof Error) { + return { error: err.message }; + } else { + return { error: 'An unknown error occurred' }; + } + } + } }