From 92b6401123d4b3f11dd6901cecf1753281586600 Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Mon, 26 May 2025 14:39:32 +0530 Subject: [PATCH] added processingcenter pkg api in carnet application module --- .../carnet-application.dto.ts | 4 + .../carnet-application.controller.ts | 27 ++- .../carnet-application.service.ts | 188 +++++++++++++++++- 3 files changed, 211 insertions(+), 8 deletions(-) diff --git a/src/dto/carnet-application/carnet-application.dto.ts b/src/dto/carnet-application/carnet-application.dto.ts index 04ac4e8..3972009 100644 --- a/src/dto/carnet-application/carnet-application.dto.ts +++ b/src/dto/carnet-application/carnet-application.dto.ts @@ -36,3 +36,7 @@ export class TransmitApplicationtoProcessDTO extends IntersectionType( SPID_DTO, USERID_DTO, HEADERID_DTO ) { } +// processing [ PROCESSINGCENTER_PKG ] + +export class CarnetProcessingCenterDTO extends(IntersectionType(USERID_DTO,HEADERID_DTO)){} + diff --git a/src/oracle/carnet-application/carnet-application.controller.ts b/src/oracle/carnet-application/carnet-application.controller.ts index 4466c5e..4ef3497 100644 --- a/src/oracle/carnet-application/carnet-application.controller.ts +++ b/src/oracle/carnet-application/carnet-application.controller.ts @@ -1,7 +1,7 @@ -import { Body, Controller, Post } from '@nestjs/common'; +import { Body, Controller, Patch, Post } from '@nestjs/common'; import { CarnetApplicationService } from './carnet-application.service'; import { ApiTags } from '@nestjs/swagger'; -import { SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO } from 'src/dto/carnet-application/carnet-application.dto'; +import { CarnetProcessingCenterDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO } from 'src/dto/carnet-application/carnet-application.dto'; @ApiTags('Carnet Application - Oracle') @Controller('oracle') @@ -17,5 +17,26 @@ export class CarnetApplicationController { @Post('TransmitApplicationtoProcess') TransmitApplicationtoProcess(@Body() body: TransmitApplicationtoProcessDTO) { return this.carnetApplicationService.TransmitApplicationtoProcess(body); - } + } + + @Patch('ProcessOriginalCarnet') + ProcessOriginalCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.ProcessOriginalCarnet(body); + } + @Patch('UpdatePrintCarnet') + UpdatePrintCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.UpdatePrintCarnet(body); + } + @Patch('VoidCarnet') + VoidCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.VoidCarnet(body); + } + @Patch('DuplicateCarnet') + DuplicateCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.DuplicateCarnet(body); + } + @Patch('CloseCarnet') + CloseCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.CloseCarnet(body); + } } diff --git a/src/oracle/carnet-application/carnet-application.service.ts b/src/oracle/carnet-application/carnet-application.service.ts index 50a3e7c..2f58f50 100644 --- a/src/oracle/carnet-application/carnet-application.service.ts +++ b/src/oracle/carnet-application/carnet-application.service.ts @@ -1,6 +1,6 @@ import { Injectable, Logger } from '@nestjs/common'; import { OracleDBService } from 'src/db/db.service'; -import { SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO } from 'src/dto/carnet-application/carnet-application.dto'; +import { CarnetProcessingCenterDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO } from 'src/dto/carnet-application/carnet-application.dto'; import * as oracledb from 'oracledb' import { InternalServerException } from 'src/exceptions/internalServerError.exception'; import { closeOracleDbConnection, fetchCursor, handleError } from 'src/utils/helper'; @@ -198,7 +198,7 @@ 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 } + // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); @@ -211,7 +211,7 @@ export class CarnetApplicationService { throw new InternalServerException("Incomplete data received from the database."); } - return await fetchCursor(outBinds.p_cursor, CarnetApplicationService.name); + return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally { @@ -235,7 +235,7 @@ export class CarnetApplicationService { P_USERID: { val: body.p_spid, type: oracledb.DB_TYPE_NUMBER }, 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: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); @@ -248,7 +248,185 @@ export class CarnetApplicationService { throw new InternalServerException("Incomplete data received from the database."); } - return await fetchCursor(outBinds.p_cursor, CarnetApplicationService.name); + return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + + // processing [ PROCESSINGCENTER_PKG ] + + async ProcessOriginalCarnet(body: CarnetProcessingCenterDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.ProcessOriginalCarnet( + :P_USERID, :P_HEADERID :P_CURSOR + ); + END;`, + { + P_USERID: { val: body.p_userid, type: oracledb.DB_TYPE_NUMBER }, + 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 } + }, + { 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."); + } + + return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + async UpdatePrintCarnet(body: CarnetProcessingCenterDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.UpdatePrintCarnet( + :P_USERID, :P_HEADERID :P_CURSOR + ); + END;`, + { + P_USERID: { val: body.p_userid, type: oracledb.DB_TYPE_NUMBER }, + 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 } + }, + { 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."); + } + + return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + async VoidCarnet(body: CarnetProcessingCenterDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.VoidCarnet( + :P_USERID, :P_HEADERID :P_CURSOR + ); + END;`, + { + P_USERID: { val: body.p_userid, type: oracledb.DB_TYPE_NUMBER }, + 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 } + }, + { 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."); + } + + return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + async DuplicateCarnet(body: CarnetProcessingCenterDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.DuplicateCarnet( + :P_USERID, :P_HEADERID :P_CURSOR + ); + END;`, + { + P_USERID: { val: body.p_userid, type: oracledb.DB_TYPE_NUMBER }, + 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 } + }, + { 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."); + } + + return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + async CloseCarnet(body: CarnetProcessingCenterDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.CloseCarnet( + :P_USERID, :P_HEADERID :P_CURSOR + ); + END;`, + { + P_USERID: { val: body.p_userid, type: oracledb.DB_TYPE_NUMBER }, + 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 } + }, + { 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."); + } + + return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); } catch (error) { handleError(error, CarnetApplicationService.name) } finally {