From 0376034dec9ab1387838d99ba4a2259cce6a7a85 Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Wed, 13 Aug 2025 10:45:58 +0530 Subject: [PATCH] new apis --- .../carnet-application-property.dto.ts | 104 +++++- .../carnet-application.dto.ts | 20 +- .../carnet-application.controller.ts | 45 ++- .../carnet-application.service.ts | 297 ++++++++++++++++-- src/oracle/oracle.service.ts | 57 +++- 5 files changed, 477 insertions(+), 46 deletions(-) diff --git a/src/dto/carnet-application/carnet-application-property.dto.ts b/src/dto/carnet-application/carnet-application-property.dto.ts index 66882e4..1433faa 100644 --- a/src/dto/carnet-application/carnet-application-property.dto.ts +++ b/src/dto/carnet-application/carnet-application-property.dto.ts @@ -52,6 +52,40 @@ export class APPLICATIONNAME_DTO { P_APPLICATIONNAME: string; } +export class GOODS_PORT_DTO { + @ApiProperty({ required: true }) + @IsString({ message: 'Property P_GOODSPORT must be a string' }) + @IsDefined({ message: 'Property P_GOODSPORT is required' }) + P_GOODSPORT: string; +} + +export class GOODS_COUNTRY_DTO { + @ApiProperty({ required: true }) + @IsString({ message: 'Property P_GOODSCOUNTRY must be a string' }) + @IsDefined({ message: 'Property P_GOODSCOUNTRY is required' }) + P_GOODSCOUNTRY: string; +} + +export class REASON_CODE_DTO { + @ApiProperty({ required: true }) + @IsString({ message: 'Property P_REASONCODE must be a string' }) + @IsDefined({ message: 'Property P_REASONCODE is required' }) + P_REASONCODE: string; +} + +export class EXTENSION_PERIOD_DTO { + @ApiProperty({ required: true }) + @Max(999999999, { + message: 'Property P_EXTENSIONPERIOD must not exceed 999999999', + }) + @Min(0, { message: 'Property P_EXTENSIONPERIOD must be at least 0 or more' }) + @IsInt({ message: 'Property P_EXTENSIONPERIOD allows only whole numbers' }) + @IsNumber({}, { message: 'Property P_EXTENSIONPERIOD must be a number' }) + @Transform(({ value }) => Number(value)) + @IsDefined({ message: 'Property P_EXTENSIONPERIOD is required' }) + P_EXTENSIONPERIOD: number; +} + export class ORDERTYPE_DTO { @ApiProperty({ required: true }) @IsString({ message: 'Property P_ORDERTYPE must be a string' }) @@ -170,6 +204,63 @@ export class GLTABLE_ROW_DTO { GOODSORIGINCOUNTRY: string; } +export class GLTABLE_ROW_ADD_DTO { + @ApiProperty({ required: false }) + @Max(99999, { message: 'Property ITEMNO must not exceed 99999' }) + @Min(0, { message: 'Property ITEMNO must be at least 0 or more' }) + @IsInt({ message: 'Property ITEMNO allows only whole numbers' }) + @Transform(({ value }) => { + if (value === undefined || value === null || value === '') return 0; + return Number(value); + }) + @IsNumber({}, { message: 'Property ITEMNO must be a number' }) + @IsOptional() + ITEMNO: number = 0 + + @ApiProperty({ required: true }) + @MaxLength(200, { message: 'Property ITEMDESCRIPTION must not exceed 200 characters' }) + @IsString({ message: 'Property ITEMDESCRIPTION must be a string' }) + @IsDefined({ message: 'Property ITEMDESCRIPTION is required' }) + ITEMDESCRIPTION: string; + + @ApiProperty({ required: true }) + @Max(999999999.99, { message: 'Property ITEMVALUE must not exceed 999999999.99' }) + @Min(0, { message: 'Property ITEMVALUE must be at least 0 or more' }) + @Transform(({ value }) => Number(value)) + @IsNumber({ maxDecimalPlaces: 2 }, { message: 'Property ITEMVALUE must be a number' }) + @IsDefined({ message: 'Property ITEMVALUE is required' }) + ITEMVALUE: number; + + @ApiProperty({ required: true }) + @Max(99999, { message: 'Property NOOFPIECES must not exceed 99999' }) + @Min(0, { message: 'Property NOOFPIECES must be at least 0 or more' }) + @IsInt({ message: 'Property NOOFPIECES allows only whole numbers' }) + @Transform(({ value }) => Number(value)) + @IsNumber({}, { message: 'Property NOOFPIECES must be a number' }) + @IsDefined({ message: 'Property NOOFPIECES is required' }) + NOOFPIECES: number; + + @ApiProperty({ required: true }) + @Max(99999.9999, { message: 'Property ITEMVALUE must not exceed 999999999.99' }) + @Min(0, { message: 'Property ITEMVALUE must be at least 0 or more' }) + @Transform(({ value }) => Number(value)) + @IsNumber({ maxDecimalPlaces: 2 }, { message: 'Property ITEMVALUE must be a number' }) + @IsDefined({ message: 'Property ITEMVALUE is required' }) + ITEMWEIGHT: number; + + @ApiProperty({ required: true }) + @MaxLength(10, { message: 'Property ITEMWEIGHTUOM must not exceed 10 characters' }) + @IsString({ message: 'Property ITEMWEIGHTUOM must be a string' }) + @IsDefined({ message: 'Property ITEMWEIGHTUOM is required' }) + ITEMWEIGHTUOM: string; + + @ApiProperty({ required: true }) + @MaxLength(2, { message: 'Property GOODSORIGINCOUNTRY must not exceed 2 characters' }) + @IsString({ message: 'Property GOODSORIGINCOUNTRY must be a string' }) + @IsDefined({ message: 'Property GOODSORIGINCOUNTRY is required' }) + GOODSORIGINCOUNTRY: string; +} + export class GLTABLE_DTO { @ApiProperty({ required: true, type: () => [GLTABLE_ROW_DTO] }) @Type(() => GLTABLE_ROW_DTO) @@ -179,7 +270,16 @@ export class GLTABLE_DTO { P_GLTABLE: GLTABLE_ROW_DTO[]; } -export class ITEMNO_DTO{ +export class GLTABLE_ITEMNO_OPTIONAL_DTO { + @ApiProperty({ required: true, type: () => [GLTABLE_ROW_ADD_DTO] }) + @Type(() => GLTABLE_ROW_ADD_DTO) + @ValidateNested({ each: true }) + @IsArray({ message: 'Property P_GLTABLE allows only array type' }) + @IsDefined({ message: 'Property P_GLTABLE is required' }) + P_GLTABLE: GLTABLE_ROW_ADD_DTO[]; +} + +export class ITEMNO_DTO { @ApiProperty({ required: true }) @Max(99999, { message: 'Property ITEMNO must not exceed 99999' }) @Min(0, { message: 'Property ITEMNO must be at least 0 or more' }) @@ -190,7 +290,7 @@ export class ITEMNO_DTO{ P_ITEMNO: number; } -export class SHIPCONTACTID_DTO{ +export class SHIPCONTACTID_DTO { @ApiProperty({ required: true }) @Max(99999, { message: 'Property P_SHIPCONTACTID must not exceed 99999' }) @Min(0, { message: 'Property P_SHIPCONTACTID must be at least 0 or more' }) diff --git a/src/dto/carnet-application/carnet-application.dto.ts b/src/dto/carnet-application/carnet-application.dto.ts index 5ced5b8..5cdf612 100644 --- a/src/dto/carnet-application/carnet-application.dto.ts +++ b/src/dto/carnet-application/carnet-application.dto.ts @@ -3,10 +3,10 @@ import { IntersectionType, PartialType } from "@nestjs/swagger"; import { APPLICATIONNAME_DTO, AUTHREP_DTO, AUTO_FLAG_DTO, COMMERCIAL_SAMPLE_FLAG_DTO, COUNTRYTABLE_DTO, CUSTCOURIERNO_DTO, DELIVERYMETHOD_DTO, DELIVERYTYPE_DTO, - EXIBITIONS_FAIR_FLAG_DTO, FORMOFSECURITY_DTO, GLTABLE_DTO, HEADERID_DTO, + EXIBITIONS_FAIR_FLAG_DTO, EXTENSION_PERIOD_DTO, FORMOFSECURITY_DTO, GLTABLE_DTO, GLTABLE_ITEMNO_OPTIONAL_DTO, GOODS_COUNTRY_DTO, GOODS_PORT_DTO, HEADERID_DTO, HORSE_FLAG_DTO, INSPROTECTION_DTO, ITEMNO_DTO, LDIPROTECTION_DTO, ORDERTYPE_DTO, PAYMENTMETHOD_DTO, PRINTGL_DTO, - PROF_EQUIPMENT_FLAG_DTO, REFNO_DTO, SHIPADDRID_DTO, SHIPCONTACTID_DTO, SHIPNAME_DTO, SHIPTOTYPE_DTO, USSETS_DTO + PROF_EQUIPMENT_FLAG_DTO, REASON_CODE_DTO, REFNO_DTO, SHIPADDRID_DTO, SHIPCONTACTID_DTO, SHIPNAME_DTO, SHIPTOTYPE_DTO, USSETS_DTO } from "./carnet-application-property.dto"; import { ADDRESS1_DTO, ADDRESS2_DTO, CITY_DTO, COUNTRY_DTO, NOTES_DTO, SPID_DTO, STATE_DTO, USERID_DTO, ZIP_DTO } from "../uscib-managed-sp/sp/sp-property.dto"; @@ -52,8 +52,18 @@ export class TransmitApplicationtoProcessDTO extends IntersectionType( ) { } // processing [ PROCESSINGCENTER_PKG ] - +export class CopyCarnetDTO extends (IntersectionType(USERID_DTO, HEADERID_DTO, APPLICATIONNAME_DTO)) { } export class CarnetProcessingCenterDTO extends (IntersectionType(USERID_DTO, HEADERID_DTO)) { } +export class GetExtendedSectionDTO extends (IntersectionType(SPID_DTO, HEADERID_DTO)){} +export class SaveExtensionApplicationDTO extends(IntersectionType( + USERID_DTO, + SPID_DTO, + HEADERID_DTO, + GOODS_PORT_DTO, + GOODS_COUNTRY_DTO, + REASON_CODE_DTO, + EXTENSION_PERIOD_DTO +)){} export class PrintCarnetDTO extends (IntersectionType(SPID_DTO, HEADERID_DTO, PRINTGL_DTO)) { } export class PrintGLDTO extends (IntersectionType(SPID_DTO, HEADERID_DTO)) { } @@ -74,6 +84,10 @@ export class UpdateExpGoodsAuthRepDTO extends IntersectionType( ) { } export class AddGenerallistItemsDTO extends IntersectionType( + HEADERID_DTO, GLTABLE_ITEMNO_OPTIONAL_DTO, USERID_DTO +) { } + +export class EditGenerallistItemsDTO extends IntersectionType( HEADERID_DTO, GLTABLE_DTO, USERID_DTO ) { } diff --git a/src/oracle/carnet-application/carnet-application.controller.ts b/src/oracle/carnet-application/carnet-application.controller.ts index 4501405..4af3dca 100644 --- a/src/oracle/carnet-application/carnet-application.controller.ts +++ b/src/oracle/carnet-application/carnet-application.controller.ts @@ -1,4 +1,4 @@ -import { BadRequestException, Body, Controller, Delete, Get, Param, Patch, Post, Put, Res, StreamableFile, UseGuards } from '@nestjs/common'; +import { BadRequestException, Body, Controller, Delete, Get, HttpCode, Param, Patch, Post, Put, Res, StreamableFile, UseGuards } from '@nestjs/common'; import { CarnetApplicationService } from './carnet-application.service'; import { ApiTags } from '@nestjs/swagger'; @@ -7,7 +7,7 @@ import { AddCountriesDTO, AddGenerallistItemsDTO, CA_UpdateHolderDTO, - CarnetProcessingCenterDTO, CreateApplicationDTO, DeleteGenerallistItemsDTO, GetCarnetControlCenterDTO, PrintCarnetDTO, PrintGLDTO, SaveCarnetApplicationDTO, TransmitApplicationtoProcessDTO, + CarnetProcessingCenterDTO, CopyCarnetDTO, CreateApplicationDTO, DeleteGenerallistItemsDTO, EditGenerallistItemsDTO, GetCarnetControlCenterDTO, GetExtendedSectionDTO, PrintCarnetDTO, PrintGLDTO, SaveCarnetApplicationDTO, SaveExtensionApplicationDTO, TransmitApplicationtoProcessDTO, UpdateExpGoodsAuthRepDTO, UpdateShippingDetailsDTO } from 'src/dto/property.dto'; @@ -70,7 +70,7 @@ export class CarnetApplicationController { } @Put('EditGenerallistItems') - EditGenerallistItems(@Body() body: AddGenerallistItemsDTO) { + EditGenerallistItems(@Body() body: EditGenerallistItemsDTO) { return this.carnetApplicationService.EditGenerallistItems(body); } @@ -107,12 +107,38 @@ export class CarnetApplicationController { return this.carnetApplicationService.VoidCarnet(body); } + + @Patch('CopyCarnet') + CopyCarnet(@Body() body: CopyCarnetDTO) { + return this.carnetApplicationService.CopyCarnet(body); + } + @Patch('DuplicateCarnet') - @Roles('ca') DuplicateCarnet(@Body() body: CarnetProcessingCenterDTO) { return this.carnetApplicationService.DuplicateCarnet(body); } + @Patch('AddlSets') + AddlSets(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.AddlSets(body); + } + + @Patch('ExtendCarnet') + ExtendCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.ExtendCarnet(body); + } + + @Get('GetExtendedSection/:P_SPID/:P_HEADERID') + GetExtendedSection(@Param() body: GetExtendedSectionDTO) { + return this.carnetApplicationService.GetExtendedSection(body); + } + + @Post('SaveExtensionApplication') + @HttpCode(200) + SaveExtensionApplication(@Body() body: SaveExtensionApplicationDTO) { + return this.carnetApplicationService.SaveExtensionApplication(body); + } + @Patch('CloseCarnet') @Roles('sa') CloseCarnet(@Body() body: CarnetProcessingCenterDTO) { @@ -158,7 +184,7 @@ export class CarnetApplicationController { // [PRINT_PKG] @Post('PrintCarnet') - @Roles('ca', 'sa', 'ua') + @HttpCode(200) async PrintCarnet(@Body() body: PrintCarnetDTO, @Res({ passthrough: true }) res: Response) { try { @@ -203,7 +229,7 @@ export class CarnetApplicationController { } @Post('PrintGL') - @Roles('ca', 'sa', 'ua') + @HttpCode(200) async PrintGL(@Body() body: PrintGLDTO, @Res({ passthrough: true }) res: Response) { try { const { finalArray, carnetData }: any = await this.carnetApplicationService.PrintGL(body); @@ -236,7 +262,12 @@ export class CarnetApplicationController { return new StreamableFile(stream); } catch (error) { - return error.message; + if (error instanceof BadRequestException || error instanceof BR) { + throw new BadRequestException("Download failed please check the details") + } + else { + throw new InternalServerException("Error while downloading"); + } } } diff --git a/src/oracle/carnet-application/carnet-application.service.ts b/src/oracle/carnet-application/carnet-application.service.ts index b522d0c..c246efe 100644 --- a/src/oracle/carnet-application/carnet-application.service.ts +++ b/src/oracle/carnet-application/carnet-application.service.ts @@ -16,7 +16,10 @@ import { DeleteGenerallistItemsDTO, PrintCarnetDTO, PrintGLDTO, - YON + YON, + CopyCarnetDTO, + GetExtendedSectionDTO, + SaveExtensionApplicationDTO } from 'src/dto/property.dto'; import { OracleService } from '../oracle.service'; import { BadRequestException } from 'src/exceptions/badRequest.exception'; @@ -327,7 +330,7 @@ export class CarnetApplicationService { try { connection = await this.oracleDBService.getConnection(); - const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_INSTANCE(body); + const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_OPTIONAL_ITEMNO_INSTANCE(body); const result = await connection.execute( `BEGIN @@ -750,6 +753,50 @@ export class CarnetApplicationService { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } + + async CopyCarnet(body: CopyCarnetDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.CopyCarnet( + :P_USERID, :P_HEADERID, :P_APPLICATIONNAME, :P_CURSOR + ); + END;`, + { + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, + P_APPLICATIONNAME: { val: body.P_APPLICATIONNAME, type: oracledb.DB_TYPE_NVARCHAR }, + 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."); + } + + const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Copied Successfully", ...fres[0] }; + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } async DuplicateCarnet(body: CarnetProcessingCenterDTO) { let connection; try { @@ -792,6 +839,181 @@ export class CarnetApplicationService { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } + async AddlSets(body: CarnetProcessingCenterDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.AddlSets( + :P_USERID, :P_HEADERID, :P_CURSOR + ); + END;`, + { + 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 } + }, + { 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, CarnetApplicationService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Additional sets completed", ...fres[0] }; + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + async ExtendCarnet(body: CarnetProcessingCenterDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.ExtendCarnet( + :P_USERID, :P_HEADERID, :P_CURSOR + ); + END;`, + { + 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 } + }, + { 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, CarnetApplicationService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Extended successfully", ...fres[0] }; + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + async GetExtendedSection(body: GetExtendedSectionDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.GetExtendedSection( + :P_SPID, :P_HEADERID, :P_CURSOR + ); + END;`, + { + P_SPID: { 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 } + }, + { 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, CarnetApplicationService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + // return { statusCode: 200, message: "Extended successfully", ...fres[0] }; + return fres; + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + async SaveExtensionApplication(body: SaveExtensionApplicationDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + PROCESSINGCENTER_PKG.SaveExtensionApplication( + :P_USERID, :P_SPID, :P_HEADERID, :P_GOODSPORT, :P_GOODSCOUNTRY, :P_REASONCODE, :P_EXTENSIONPERIOD, :P_CURSOR + ); + END;`, + { + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, + P_GOODSPORT: { val: body.P_GOODSPORT, type: oracledb.DB_TYPE_NVARCHAR }, + P_GOODSCOUNTRY: { val: body.P_GOODSCOUNTRY, type: oracledb.DB_TYPE_NVARCHAR }, + P_REASONCODE: { val: body.P_REASONCODE, type: oracledb.DB_TYPE_NVARCHAR }, + P_EXTENSIONPERIOD: { val: body.P_EXTENSIONPERIOD, 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."); + } + + const fres: any = await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + + if (fres.length > 0 && fres[0].ERRORMESG) { + this.logger.warn(fres[0].ERRORMESG); + throw new BadRequestException(fres[0].ERRORMESG) + } + + return { statusCode: 200, message: "Saved successfully", ...fres[0] }; + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + async CloseCarnet(body: CarnetProcessingCenterDTO) { let connection; try { @@ -1159,6 +1381,8 @@ export class CarnetApplicationService { throw new BadRequestException(fres[0].ERRORMESG) } + // console.log(fres, "\n", "--------------------", fres1.length > 0 ? fres[0] : []); + return { fres: fres, fres1: fres1 } } catch (error) { @@ -1173,8 +1397,15 @@ export class CarnetApplicationService { try { const { fres, fres1 }: any = await this.getPrintingData(body); - if (fres.length === 0 || fres1.length === 0) { - throw new BadRequestException("Print failed please check the submitted details"); + if (body.P_PRINTGL === 'Y') { + if (fres.length === 0 || fres1.length === 0) { + throw new BadRequestException("Print failed please check the submitted details"); + } + } + else { + if (fres.length === 0) { + throw new BadRequestException("Print failed please check the submitted details"); + } } if (fres.length > 0 && fres[0].ERRORMESG) { @@ -1183,7 +1414,7 @@ export class CarnetApplicationService { } try { - const glData: pdfGLData[] = fres1.map(x => { + const glData: pdfGLData[] = fres1.map((x: any) => { return { itemNo: x.ITEMNO, description: x.ITEMDESCRIPTION, @@ -1195,20 +1426,20 @@ export class CarnetApplicationService { }); const carnetData: pdfCarnetData = { - carnetNo: fres[0].CARNETNO, - ISSUEDBY: fres[0].ISSUEDBY, - ISSUEDATE: fres[0].ISSUEDATE, - EXPDATE: fres[0].EXPDATE, - AUTHREP: fres[0].AUTHREP, - NOOFUSSETS: fres[0].NOOFUSSETS, - NOOFFOREIGNSETS: fres[0].NOOFFOREIGNSETS, - NOOFTRANSITSETS: fres[0].NOOFTRANSITSETS, - PRINTGOODSTOBEEXPORTED: fres[0].PRINTGOODSTOBEEXPORTED, - HOLDERDATATOPRINT: fres[0].HOLDERDATATOPRINT, - CONTINUATIONSHEETS: fres[0].CONTINUATIONSHEETS, - NEXTUSCFNO: fres[0].NEXTUSCFNO, - NEXTFOREIGNCFNO: fres[0].NEXTFOREIGNCFNO, - NEXTTRANSITCFNO: fres[0].NEXTTRANSITCFNO, + carnetNo: fres[0].CARNETNO ?? "", + ISSUEDBY: fres[0].ISSUEDBY ?? "", + ISSUEDATE: fres[0].ISSUEDATE ?? "", + EXPDATE: fres[0].EXPDATE ?? "", + AUTHREP: fres[0].AUTHREP ?? "", + NOOFUSSETS: fres[0].NOOFUSSETS ?? 0, + NOOFFOREIGNSETS: fres[0].NOOFFOREIGNSETS ?? 0, + NOOFTRANSITSETS: fres[0].NOOFTRANSITSETS ?? 0, + PRINTGOODSTOBEEXPORTED: fres[0].PRINTGOODSTOBEEXPORTED ?? "", + HOLDERDATATOPRINT: fres[0].HOLDERDATATOPRINT ?? "", + CONTINUATIONSHEETS: fres[0].CONTINUATIONSHEETS ?? 0, + NEXTUSCFNO: fres[0].NEXTUSCFNO ?? 0, + NEXTFOREIGNCFNO: fres[0].NEXTFOREIGNCFNO ?? 0, + NEXTTRANSITCFNO: fres[0].NEXTTRANSITCFNO ?? 0, contPageNo: 0 } @@ -1291,20 +1522,20 @@ export class CarnetApplicationService { }); const carnetData: pdfCarnetData = { - carnetNo: fres[0].CARNETNO, - ISSUEDBY: fres[0].ISSUEDBY, - ISSUEDATE: fres[0].ISSUEDATE, - EXPDATE: fres[0].EXPDATE, - AUTHREP: fres[0].AUTHREP, - NOOFUSSETS: fres[0].NOOFUSSETS, - NOOFFOREIGNSETS: fres[0].NOOFFOREIGNSETS, - NOOFTRANSITSETS: fres[0].NOOFTRANSITSETS, - PRINTGOODSTOBEEXPORTED: fres[0].PRINTGOODSTOBEEXPORTED, - HOLDERDATATOPRINT: fres[0].HOLDERDATATOPRINT, - CONTINUATIONSHEETS: fres[0].CONTINUATIONSHEETS, - NEXTUSCFNO: fres[0].NEXTUSCFNO, - NEXTFOREIGNCFNO: fres[0].NEXTFOREIGNCFNO, - NEXTTRANSITCFNO: fres[0].NEXTTRANSITCFNO, + carnetNo: fres[0].CARNETNO ?? "", + ISSUEDBY: fres[0].ISSUEDBY ?? "", + ISSUEDATE: fres[0].ISSUEDATE ?? "", + EXPDATE: fres[0].EXPDATE ?? "", + AUTHREP: fres[0].AUTHREP ?? "", + NOOFUSSETS: fres[0].NOOFUSSETS ?? 0, + NOOFFOREIGNSETS: fres[0].NOOFFOREIGNSETS ?? 0, + NOOFTRANSITSETS: fres[0].NOOFTRANSITSETS ?? 0, + PRINTGOODSTOBEEXPORTED: fres[0].PRINTGOODSTOBEEXPORTED ?? "", + HOLDERDATATOPRINT: fres[0].HOLDERDATATOPRINT ?? "", + CONTINUATIONSHEETS: fres[0].CONTINUATIONSHEETS ?? 0, + NEXTUSCFNO: fres[0].NEXTUSCFNO ?? 0, + NEXTFOREIGNCFNO: fres[0].NEXTFOREIGNCFNO ?? 0, + NEXTTRANSITCFNO: fres[0].NEXTTRANSITCFNO ?? 0, contPageNo: 0 } diff --git a/src/oracle/oracle.service.ts b/src/oracle/oracle.service.ts index eb53a72..8714b57 100644 --- a/src/oracle/oracle.service.ts +++ b/src/oracle/oracle.service.ts @@ -1,6 +1,6 @@ import { Injectable, Logger } from "@nestjs/common"; import { OracleDBService } from "src/db/db.service"; -import { CLIENTLOCADDRESSTABLE_ROW_DTO, CONTACTSTABLE_ROW_DTO, COUNTRYTABLE_DTO, COUNTRYTABLE_ROW_DTO, GLTABLE_DTO, GLTABLE_ROW_DTO } from "src/dto/property.dto"; +import { CLIENTLOCADDRESSTABLE_ROW_DTO, CONTACTSTABLE_ROW_DTO, COUNTRYTABLE_DTO, COUNTRYTABLE_ROW_DTO, GLTABLE_DTO, GLTABLE_ITEMNO_OPTIONAL_DTO, GLTABLE_ROW_ADD_DTO, GLTABLE_ROW_DTO } from "src/dto/property.dto"; import { InternalServerException } from "src/exceptions/internalServerError.exception"; import { closeOracleDbConnection, handleError } from "src/utils/helper"; @@ -10,6 +10,61 @@ export class OracleService { constructor(private readonly oracleDBService: OracleDBService) { } + async get_GL_TABLE_OPTIONAL_ITEMNO_INSTANCE(finalBody: any) { + + // P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' } + // P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT } + + let connection; + + try { + connection = await this.oracleDBService.getConnection(); + + 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, + } + ); + return result.rows[0][0]; + } + + const GLTABLE_ARRAY: GLTABLE_ITEMNO_OPTIONAL_DTO = { + P_GLTABLE: await Promise.all( + (finalBody.P_GLTABLE ?? []).map(async (x: GLTABLE_ROW_ADD_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 ?? []); + + return GLTABLE_INSTANCE; + + } catch (error) { + throw new Error("Error occured completing this process") + } finally { + await closeOracleDbConnection(connection, OracleService.name) + } + } + async get_GL_TABLE_INSTANCE(finalBody: any) { // P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }