From 69226ffca5e788c6f33efe6b5c41f263ef80556a Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Mon, 22 Sep 2025 15:39:38 +0530 Subject: [PATCH] uppercase all response keys --- .../carnet-application.controller.ts | 160 ++--- .../carnet-application.service.ts | 589 +++++++++++++++++- .../manage-clients/manage-clients.service.ts | 30 +- src/pg/manage-fee/manage-fee.service.ts | 44 +- src/pg/manage-holder/manage-holder.service.ts | 24 +- src/pg/param-table/param-table.service.ts | 18 +- .../carnet-sequence.service.ts | 6 +- .../uscib-managed-sp/region/region.service.ts | 8 +- .../sp-contacts/sp-contacts.service.ts | 10 +- src/pg/uscib-managed-sp/sp/sp.service.ts | 12 +- .../user-maintenance.controller.ts | 8 +- .../user-maintenance.service.ts | 92 +-- src/utils/helper.ts | 28 +- 13 files changed, 802 insertions(+), 227 deletions(-) diff --git a/src/pg/carnet-application/carnet-application.controller.ts b/src/pg/carnet-application/carnet-application.controller.ts index 1998bdb..bf1c2cd 100644 --- a/src/pg/carnet-application/carnet-application.controller.ts +++ b/src/pg/carnet-application/carnet-application.controller.ts @@ -53,107 +53,107 @@ export class CarnetApplicationController { return this.carnetApplicationService.UpdateHolder(body); } - // @Patch('UpdateExpGoodsAuthRep') - // UpdateExpGoodsAuthRep(@Body() body: UpdateExpGoodsAuthRepDTO) { - // return this.carnetApplicationService.UpdateExpGoodsAuthRep(body); - // } + @Patch('UpdateExpGoodsAuthRep') + UpdateExpGoodsAuthRep(@Body() body: UpdateExpGoodsAuthRepDTO) { + return this.carnetApplicationService.UpdateExpGoodsAuthRep(body); + } - // @Post('AddGenerallistItems') - // AddGenerallistItems(@Body() body: AddGenerallistItemsDTO) { - // return this.carnetApplicationService.AddGenerallistItems(body); - // } + @Post('AddGenerallistItems') + AddGenerallistItems(@Body() body: AddGenerallistItemsDTO) { + return this.carnetApplicationService.AddGenerallistItems(body); + } - // @Post('AddCountries') - // AddCountries(@Body() body: AddCountriesDTO) { - // return this.carnetApplicationService.AddCountries(body); - // } + @Post('AddCountries') + AddCountries(@Body() body: AddCountriesDTO) { + return this.carnetApplicationService.AddCountries(body); + } - // @Put('EditGenerallistItems') - // EditGenerallistItems(@Body() body: EditGenerallistItemsDTO) { - // return this.carnetApplicationService.EditGenerallistItems(body); - // } + @Put('EditGenerallistItems') + EditGenerallistItems(@Body() body: EditGenerallistItemsDTO) { + return this.carnetApplicationService.EditGenerallistItems(body); + } - // @Delete('DeleteGenerallistItems') - // DeleteGenerallistItems(@Body() body: DeleteGenerallistItemsDTO) { - // return this.carnetApplicationService.DeleteGenerallistItems(body); - // } + @Delete('DeleteGenerallistItems') + DeleteGenerallistItems(@Body() body: DeleteGenerallistItemsDTO) { + return this.carnetApplicationService.DeleteGenerallistItems(body); + } - // @Patch('UpdateShippingDetails') - // UpdateShippingDetails(@Body() body: UpdateShippingDetailsDTO) { - // return this.carnetApplicationService.UpdateShippingDetails(body); - // } + @Patch('UpdateShippingDetails') + UpdateShippingDetails(@Body() body: UpdateShippingDetailsDTO) { + return this.carnetApplicationService.UpdateShippingDetails(body); + } - // @Get('EstimatedFees/:P_SPID/:P_USERID/:P_HEADERID') - // EstimatedFees(@Param() body: GetCarnetControlCenterDTO) { - // return this.carnetApplicationService.EstimatedFees(body); - // } + @Get('EstimatedFees/:P_SPID/:P_USERID/:P_HEADERID') + EstimatedFees(@Param() body: GetCarnetControlCenterDTO) { + return this.carnetApplicationService.EstimatedFees(body); + } // // processing [ PROCESSINGCENTER_PKG ] - // @Patch('ProcessCarnet') - // ProcessOriginalCarnet(@Body() body: CarnetProcessingCenterDTO) { - // return this.carnetApplicationService.ProcessCarnet(body); - // } + @Patch('ProcessCarnet') + ProcessOriginalCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.ProcessCarnet(body); + } - // @Patch('UpdatePrintCarnet') - // UpdatePrintCarnet(@Body() body: CarnetProcessingCenterDTO) { - // return this.carnetApplicationService.UpdatePrintCarnet(body); - // } + @Patch('UpdatePrintCarnet') + UpdatePrintCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.UpdatePrintCarnet(body); + } - // @Patch('VoidCarnet') - // @Roles('sa') - // VoidCarnet(@Body() body: CarnetProcessingCenterDTO) { - // return this.carnetApplicationService.VoidCarnet(body); - // } + @Patch('VoidCarnet') + @Roles('sa') + VoidCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.VoidCarnet(body); + } - // @Patch('CopyCarnet') - // CopyCarnet(@Body() body: CopyCarnetDTO) { - // return this.carnetApplicationService.CopyCarnet(body); - // } + @Patch('CopyCarnet') + CopyCarnet(@Body() body: CopyCarnetDTO) { + return this.carnetApplicationService.CopyCarnet(body); + } - // @Patch('DuplicateCarnet') - // DuplicateCarnet(@Body() body: CarnetProcessingCenterDTO2) { - // return this.carnetApplicationService.DuplicateCarnet(body); - // } + @Patch('DuplicateCarnet') + DuplicateCarnet(@Body() body: CarnetProcessingCenterDTO2) { + return this.carnetApplicationService.DuplicateCarnet(body); + } - // @Patch('AddlSets') - // AddlSets(@Body() body: CarnetProcessingCenterDTO2) { - // return this.carnetApplicationService.AddlSets(body); - // } + @Patch('AddlSets') + AddlSets(@Body() body: CarnetProcessingCenterDTO2) { + return this.carnetApplicationService.AddlSets(body); + } - // @Patch('ExtendCarnet') - // ExtendCarnet(@Body() body: CarnetProcessingCenterDTO2) { - // return this.carnetApplicationService.ExtendCarnet(body); - // } + @Patch('ExtendCarnet') + ExtendCarnet(@Body() body: CarnetProcessingCenterDTO2) { + return this.carnetApplicationService.ExtendCarnet(body); + } - // @Get('GetExtendedSection/:P_SPID/:P_HEADERID') - // GetExtendedSection(@Param() body: GetExtendedSectionDTO) { - // return this.carnetApplicationService.GetExtendedSection(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); - // } + @Post('SaveExtensionApplication') + @HttpCode(200) + SaveExtensionApplication(@Body() body: SaveExtensionApplicationDTO) { + return this.carnetApplicationService.SaveExtensionApplication(body); + } - // @Patch('CloseCarnet') - // @Roles('sa') - // CloseCarnet(@Body() body: CarnetProcessingCenterDTO) { - // return this.carnetApplicationService.CloseCarnet(body); - // } + @Patch('CloseCarnet') + @Roles('sa') + CloseCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.CloseCarnet(body); + } - // @Patch('ResetCarnet') - // @Roles('sa') - // ResetCarnet(@Body() body: CarnetProcessingCenterDTO) { - // return this.carnetApplicationService.ResetCarnet(body); - // } + @Patch('ResetCarnet') + @Roles('sa') + ResetCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.ResetCarnet(body); + } - // @Delete('DeleteCarnet') - // DeleteCarnet(@Body() body: CarnetProcessingCenterDTO) { - // return this.carnetApplicationService.DeleteCarnet(body); - // } + @Delete('DeleteCarnet') + DeleteCarnet(@Body() body: CarnetProcessingCenterDTO) { + return this.carnetApplicationService.DeleteCarnet(body); + } // [ CARNETCONTROLCENTER_PKG ] diff --git a/src/pg/carnet-application/carnet-application.service.ts b/src/pg/carnet-application/carnet-application.service.ts index df487bf..40c7d07 100644 --- a/src/pg/carnet-application/carnet-application.service.ts +++ b/src/pg/carnet-application/carnet-application.service.ts @@ -26,7 +26,7 @@ import { import { BadRequestException } from 'src/exceptions/badRequest.exception'; import { PoolClient } from 'pg'; import { PgDBService } from 'src/db/db.service'; -import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; @Injectable() export class CarnetApplicationService { @@ -63,7 +63,7 @@ export class CarnetApplicationService { return { statusCode: 200, message: ResponseStatus.transmitted, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -101,7 +101,7 @@ export class CarnetApplicationService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -139,7 +139,7 @@ export class CarnetApplicationService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -177,7 +177,7 @@ export class CarnetApplicationService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -242,7 +242,7 @@ export class CarnetApplicationService { return { statusCode: 200, message: ResponseStatus.added, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -307,7 +307,7 @@ export class CarnetApplicationService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -345,7 +345,7 @@ export class CarnetApplicationService { return { statusCode: 200, message: ResponseStatus.deleted, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -406,7 +406,7 @@ export class CarnetApplicationService { return { statusCode: 200, message: ResponseStatus.added, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -417,26 +417,557 @@ export class CarnetApplicationService { } } - async UpdateShippingDetails(body: UpdateShippingDetailsDTO) { } - - async EstimatedFees(body: GetCarnetControlCenterDTO) { } + async UpdateShippingDetails(body: UpdateShippingDetailsDTO) { + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".carnetapplication_pkg_updateshippingdetails($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29) + `; + await client.query(callProcQuery, + [ + body.P_HEADERID, + body.P_SHIPTOTYPE, + body.P_SHIPCONTACTID, + body.P_SHIPNAME, + body.P_ADDRESS1, + body.P_ADDRESS2, + body.P_CITY, + body.P_STATE, + body.P_ZIP, + body.P_COUNTRY, + body.P_FIRSTNAME, + body.P_LASTNAME, + body.P_TITLE, + body.P_PHONENO, + body.P_MOBILENO, + body.P_FAXNO, + body.P_EMAILADDRESS, + body.P_MIDDLEINITIAL, + body.P_FORMOFSECURITY, + body.P_INSPROTECTION, + body.P_LDIPROTECTION, + body.P_DELIVERYTYPE, + body.P_DELIVERYMETHOD, + body.P_PAYMENTMETHOD, + body.P_CUSTCOURIERNO, + body.P_REFNO, + body.P_NOTES, + body.P_USERID, + cursorName + ]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.updated, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } + + async EstimatedFees(body: GetCarnetControlCenterDTO) { + + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".carnetapplication_pkg_estimatedfees($1, $2, $3, $4) + `; + await client.query(callProcQuery, [body.P_SPID, body.P_USERID, body.P_HEADERID, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + return toUpperCaseKeys(fetchResult.rows); + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + + } // processing [ PROCESSINGCENTER_PKG ] - async ProcessCarnet(body: CarnetProcessingCenterDTO) { } - async UpdatePrintCarnet(body: CarnetProcessingCenterDTO) { } - async VoidCarnet(body: CarnetProcessingCenterDTO) { } + async ProcessCarnet(body: CarnetProcessingCenterDTO) { + let client: PoolClient | null = null; - async CopyCarnet(body: CopyCarnetDTO) { } - async DuplicateCarnet(body: CarnetProcessingCenterDTO2) { } - async AddlSets(body: CarnetProcessingCenterDTO2) { } - async ExtendCarnet(body: CarnetProcessingCenterDTO2) { } - async GetExtendedSection(body: GetExtendedSectionDTO) { } - async SaveExtensionApplication(body: SaveExtensionApplicationDTO) { } + const cursorName = 'p_cursor'; - async CloseCarnet(body: CarnetProcessingCenterDTO) { } - async ResetCarnet(body: CarnetProcessingCenterDTO) { } - async DeleteCarnet(body: CarnetProcessingCenterDTO) { } + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_processcarnet($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.processed, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } + async UpdatePrintCarnet(body: CarnetProcessingCenterDTO) { + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_updateprintcarnet($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.updated, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } + async VoidCarnet(body: CarnetProcessingCenterDTO) { + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_voidcarnet($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.voided, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } + + async CopyCarnet(body: CopyCarnetDTO) { + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_copycarnet($1, $2, $3, $4) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, body.P_APPLICATIONNAME, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.copied, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } + async DuplicateCarnet(body: CarnetProcessingCenterDTO2) { + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_duplicatecarnet($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_CARNETNO, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.duplicated, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } + async AddlSets(body: CarnetProcessingCenterDTO2) { + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_addlsets($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_CARNETNO, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.addl_completed, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } + async ExtendCarnet(body: CarnetProcessingCenterDTO2) { + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_extendcarnet($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_CARNETNO, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.extended, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } + async GetExtendedSection(body: GetExtendedSectionDTO) { + + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_getextendedsection($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_SPID, body.P_HEADERID, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + return toUpperCaseKeys(fetchResult.rows); + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + + } + async SaveExtensionApplication(body: SaveExtensionApplicationDTO) { + + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_saveextensionapplication($1, $2, $3, $4, $5, $6, $7, $8) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_SPID, body.P_HEADERID, body.P_GOODSPORT, body.P_GOODSCOUNTRY, body.P_REASONCODE, body.P_EXTENSIONPERIOD, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.saved, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + + } + + async CloseCarnet(body: CarnetProcessingCenterDTO) { + + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_closecarnet($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.closed, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + + } + async ResetCarnet(body: CarnetProcessingCenterDTO) { + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_resetcarnet($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.reset_successfull, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } + async DeleteCarnet(body: CarnetProcessingCenterDTO) { + let client: PoolClient | null = null; + + const cursorName = 'p_cursor'; + + try { + client = await this.pgDBService.getConnection(); + + await client.query('BEGIN'); + + const callProcQuery = ` + CALL "CARNETSYS".processingcenter_pkg_deletecarnet($1, $2, $3) + `; + await client.query(callProcQuery, [body.P_USERID, body.P_HEADERID, cursorName]); + + // 🚫 DON'T quote the cursor name in FETCH + const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + + // 🚫 DON'T quote the cursor name in CLOSE + await client.query(`CLOSE ${cursorName}`); + await client.query('COMMIT'); + + checkPgUserDefinedErrors(fetchResult); + + return { + statusCode: 200, + message: ResponseStatus.deleted, + ...toUpperCaseKeys(fetchResult?.rows)[0] + }; + + } catch (error) { + if (client) await client.query('ROLLBACK'); + handlePgError(error, CarnetApplicationService.name) + } finally { + releasePgClient(client) + } + } // [ CARNETCONTROLCENTER_PKG ] @@ -462,7 +993,7 @@ export class CarnetApplicationService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -494,7 +1025,7 @@ export class CarnetApplicationService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -526,7 +1057,7 @@ export class CarnetApplicationService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -558,7 +1089,7 @@ export class CarnetApplicationService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -590,7 +1121,7 @@ export class CarnetApplicationService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); diff --git a/src/pg/manage-clients/manage-clients.service.ts b/src/pg/manage-clients/manage-clients.service.ts index e816231..b1e909d 100644 --- a/src/pg/manage-clients/manage-clients.service.ts +++ b/src/pg/manage-clients/manage-clients.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { ClientContactControlsDTO, CreateClientContactsDTO, CreateClientDataDTO, CreateClientLocationsDTO, GetClientContactByLacationIdDTO, GetClientDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from 'src/dto/property.dto'; -import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; import { PoolClient } from 'pg'; import { PgDBService } from 'src/db/db.service'; @@ -52,7 +52,7 @@ export class ManageClientsService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -105,7 +105,7 @@ export class ManageClientsService { return { statusCode: 201, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -157,7 +157,7 @@ export class ManageClientsService { return { statusCode: 201, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -208,7 +208,7 @@ export class ManageClientsService { return { statusCode: 201, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -278,7 +278,7 @@ export class ManageClientsService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -316,7 +316,7 @@ export class ManageClientsService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -354,7 +354,7 @@ export class ManageClientsService { return { statusCode: 200, message: ResponseStatus.inActivate, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -392,7 +392,7 @@ export class ManageClientsService { return { statusCode: 200, message: ResponseStatus.reActivate, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -459,7 +459,7 @@ export class ManageClientsService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -494,7 +494,7 @@ export class ManageClientsService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -528,7 +528,7 @@ export class ManageClientsService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -562,7 +562,7 @@ export class ManageClientsService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -596,7 +596,7 @@ export class ManageClientsService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -630,7 +630,7 @@ export class ManageClientsService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); diff --git a/src/pg/manage-fee/manage-fee.service.ts b/src/pg/manage-fee/manage-fee.service.ts index 741cd3f..925ace4 100644 --- a/src/pg/manage-fee/manage-fee.service.ts +++ b/src/pg/manage-fee/manage-fee.service.ts @@ -3,7 +3,7 @@ import { PgDBService } from 'src/db/db.service'; import { CreateBasicFeeDTO, CreateBondRateDTO, CreateCargoRateDTO, CreateCfFeeDTO, CreateCsFeeDTO, CreateEfFeeDTO, CreateFeeCommDTO, GetFeeGeneralDTO, UpdateBasicFeeDTO, UpdateBondRateDTO, UpdateCargoRateDTO, UpdateCfFeeDTO, UpdateCsFeeDTO, UpdateEfFeeDTO, UpdateFeeCommDTO } from 'src/dto/property.dto'; import { PoolClient } from 'pg'; -import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; @Injectable() export class ManageFeeService { @@ -35,7 +35,7 @@ export class ManageFeeService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -82,7 +82,7 @@ export class ManageFeeService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -129,7 +129,7 @@ export class ManageFeeService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -168,7 +168,7 @@ export class ManageFeeService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -219,7 +219,7 @@ export class ManageFeeService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -266,7 +266,7 @@ export class ManageFeeService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -305,7 +305,7 @@ export class ManageFeeService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -353,7 +353,7 @@ export class ManageFeeService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -400,7 +400,7 @@ export class ManageFeeService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -438,7 +438,7 @@ export class ManageFeeService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -488,7 +488,7 @@ export class ManageFeeService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -535,7 +535,7 @@ export class ManageFeeService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -575,7 +575,7 @@ export class ManageFeeService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -622,7 +622,7 @@ export class ManageFeeService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -668,7 +668,7 @@ export class ManageFeeService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -707,7 +707,7 @@ export class ManageFeeService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -757,7 +757,7 @@ export class ManageFeeService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -803,7 +803,7 @@ export class ManageFeeService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -842,7 +842,7 @@ export class ManageFeeService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -888,7 +888,7 @@ export class ManageFeeService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -934,7 +934,7 @@ export class ManageFeeService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { diff --git a/src/pg/manage-holder/manage-holder.service.ts b/src/pg/manage-holder/manage-holder.service.ts index 8e8513b..e51ca51 100644 --- a/src/pg/manage-holder/manage-holder.service.ts +++ b/src/pg/manage-holder/manage-holder.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { PgDBService } from 'src/db/db.service'; import { CONTACTSTABLE_ROW_DTO, CreateHolderContactsDTO, CreateHoldersDTO, GetHolderDTO, HolderActivateOrInactivateDTO, HolderContactActivateOrInactivateDTO, UpdateHolderContactDTO, UpdateHolderDTO } from 'src/dto/property.dto'; import { PoolClient } from 'pg'; -import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; @Injectable() export class ManageHolderService { @@ -55,7 +55,7 @@ export class ManageHolderService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -122,7 +122,7 @@ export class ManageHolderService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {}, + ...toUpperCaseKeys(fetchResult?.rows)[0], }; } catch (error) { if (client) await client.query('ROLLBACK'); @@ -179,7 +179,7 @@ export class ManageHolderService { return { statusCode: 201, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -214,7 +214,7 @@ export class ManageHolderService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -265,7 +265,7 @@ export class ManageHolderService { return { statusCode: 201, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -300,7 +300,7 @@ export class ManageHolderService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -337,7 +337,7 @@ export class ManageHolderService { return { statusCode: 200, message: ResponseStatus.inActivate, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -375,7 +375,7 @@ export class ManageHolderService { return { statusCode: 200, message: ResponseStatus.reActivate, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -413,7 +413,7 @@ export class ManageHolderService { return { statusCode: 200, message: ResponseStatus.inActivate, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -451,7 +451,7 @@ export class ManageHolderService { return { statusCode: 200, message: ResponseStatus.reActivate, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -486,7 +486,7 @@ export class ManageHolderService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); diff --git a/src/pg/param-table/param-table.service.ts b/src/pg/param-table/param-table.service.ts index 83aab86..d70dfb5 100644 --- a/src/pg/param-table/param-table.service.ts +++ b/src/pg/param-table/param-table.service.ts @@ -2,7 +2,7 @@ import { Injectable, Logger } from '@nestjs/common'; import { PoolClient } from 'pg'; import { PgDBService } from 'src/db/db.service'; import { ActivateOrInactivateParamRecordDTO, CreateParamRecordDTO, CreateTableRecordDTO, getParamValuesDTO, SPID_DTO, UpdateParamRecordDTO } from 'src/dto/property.dto'; -import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; @Injectable() export class ParamTableService { @@ -32,7 +32,7 @@ export class ParamTableService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -64,7 +64,7 @@ export class ParamTableService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -95,7 +95,7 @@ export class ParamTableService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -129,8 +129,10 @@ export class ParamTableService { checkPgUserDefinedErrors(fetchResult); + let fr: any = toUpperCaseKeys(fetchResult?.rows) + // return fetchResult.rows; - return { statusCode: 201, message: ResponseStatus.created, ...fetchResult?.rows[0] }; + return { statusCode: 201, message: ResponseStatus.created, ...fr[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); @@ -181,11 +183,13 @@ export class ParamTableService { checkPgUserDefinedErrors(fetchResult); + let fr: any = toUpperCaseKeys(fetchResult?.rows) + // Return response return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...fr[0] || {} }; } catch (error) { @@ -239,7 +243,7 @@ export class ParamTableService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { diff --git a/src/pg/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts b/src/pg/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts index cb97120..285e6c8 100644 --- a/src/pg/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts +++ b/src/pg/uscib-managed-sp/carnet-sequence/carnet-sequence.service.ts @@ -4,7 +4,7 @@ import { CreateCarnetSequenceDTO, SPID_DTO } from 'src/dto/property.dto'; import { InternalServerException } from 'src/exceptions/internalServerError.exception'; import { PoolClient } from 'pg'; -import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; @Injectable() @@ -37,7 +37,7 @@ export class CarnetSequenceService { checkPgUserDefinedErrors(fetchResult); - return { statusCode: 201, message: ResponseStatus.created, ...fetchResult?.rows[0] }; + return { statusCode: 201, message: ResponseStatus.created, ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { if (client) await client.query('ROLLBACK'); @@ -69,7 +69,7 @@ export class CarnetSequenceService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); diff --git a/src/pg/uscib-managed-sp/region/region.service.ts b/src/pg/uscib-managed-sp/region/region.service.ts index cb24d32..531f166 100644 --- a/src/pg/uscib-managed-sp/region/region.service.ts +++ b/src/pg/uscib-managed-sp/region/region.service.ts @@ -4,7 +4,7 @@ import { InsertRegionsDto, SPID_DTO, UpdateRegionDto } from 'src/dto/property.dt import { InternalServerException } from 'src/exceptions/internalServerError.exception'; import { PoolClient } from 'pg'; -import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; @Injectable() export class RegionService { @@ -39,7 +39,7 @@ export class RegionService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -74,7 +74,7 @@ export class RegionService { checkPgUserDefinedErrors(fetchResult); - return { statusCode: 200, message: ResponseStatus.updated, ...fetchResult?.rows[0] || {} }; + return { statusCode: 200, message: ResponseStatus.updated, ...toUpperCaseKeys(fetchResult?.rows)[0] || {} }; } catch (error) { if (client) await client.query('ROLLBACK'); @@ -107,7 +107,7 @@ export class RegionService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); diff --git a/src/pg/uscib-managed-sp/sp-contacts/sp-contacts.service.ts b/src/pg/uscib-managed-sp/sp-contacts/sp-contacts.service.ts index 333bd04..414762a 100644 --- a/src/pg/uscib-managed-sp/sp-contacts/sp-contacts.service.ts +++ b/src/pg/uscib-managed-sp/sp-contacts/sp-contacts.service.ts @@ -4,7 +4,7 @@ import { InternalServerException } from 'src/exceptions/internalServerError.exce import { PoolClient } from 'pg'; import { PgDBService } from 'src/db/db.service'; -import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; @Injectable() export class SpContactsService { @@ -52,7 +52,7 @@ export class SpContactsService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -128,7 +128,7 @@ export class SpContactsService { return { statusCode: 200, message: ResponseStatus.updated, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -194,7 +194,7 @@ export class SpContactsService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -228,7 +228,7 @@ export class SpContactsService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); diff --git a/src/pg/uscib-managed-sp/sp/sp.service.ts b/src/pg/uscib-managed-sp/sp/sp.service.ts index 7b583cb..d32b2c6 100644 --- a/src/pg/uscib-managed-sp/sp/sp.service.ts +++ b/src/pg/uscib-managed-sp/sp/sp.service.ts @@ -4,7 +4,7 @@ import { InsertNewServiceProviderDTO, SPID_DTO, UpdateServiceProviderDTO } from import { InternalServerException } from 'src/exceptions/internalServerError.exception'; import { PoolClient } from 'pg'; -import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; @Injectable() export class SpService { @@ -67,12 +67,12 @@ export class SpService { checkPgUserDefinedErrors(fetchResult); - return { statusCode: 201, message: ResponseStatus.created, ...fetchResult?.rows[0] || {} }; + return { statusCode: 201, message: ResponseStatus.created, ...toUpperCaseKeys(fetchResult?.rows)[0] || {} }; } catch (error) { if (client) await client.query('ROLLBACK'); console.log(" i went through here ... "); - + handlePgError(error, SpService.name) } finally { releasePgClient(client) @@ -125,7 +125,7 @@ export class SpService { checkPgUserDefinedErrors(fetchResult); - return { statusCode: 201, message: ResponseStatus.created, ...fetchResult?.rows[0] || {} }; + return { statusCode: 201, message: ResponseStatus.created, ...toUpperCaseKeys(fetchResult?.rows)[0] || {} }; } catch (error) { if (client) await client.query('ROLLBACK'); @@ -158,7 +158,7 @@ export class SpService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -192,7 +192,7 @@ export class SpService { await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - return fetchResult.rows; + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); diff --git a/src/pg/user-maintenance/user-maintenance.controller.ts b/src/pg/user-maintenance/user-maintenance.controller.ts index 8baaca2..944b15b 100644 --- a/src/pg/user-maintenance/user-maintenance.controller.ts +++ b/src/pg/user-maintenance/user-maintenance.controller.ts @@ -16,11 +16,15 @@ export class UserMaintenanceController { // SP_USER_DETAILS - // @Get('GetUserDetails/:P_USERID') - async GetPreparers(@Param() params: USERID_DTO) { + // [spclientuser_pkg] + + @Get('GetUserDetails/:P_USERID') + async GetSPUserDetails(@Param() params: USERID_DTO) { return await this.userMaintenanceService.GetSPUserDetails(params); } + // [userlogin_pkg] + @Patch('LockUserAccount') async LockUserAccount(@Body() body: SPID_EMAIL_DTO) { return await this.userMaintenanceService.LockUserAccount(body); diff --git a/src/pg/user-maintenance/user-maintenance.service.ts b/src/pg/user-maintenance/user-maintenance.service.ts index 0d4760c..b703863 100644 --- a/src/pg/user-maintenance/user-maintenance.service.ts +++ b/src/pg/user-maintenance/user-maintenance.service.ts @@ -1,6 +1,6 @@ import { forwardRef, Inject, Injectable, Logger } from '@nestjs/common'; import { CreateClientLoginsDTO, CreateSPLoginsDTO, CreateUSCIBLoginsDTO, EMAIL_DTO, SPID_CLIENTID_DTO, SPID_DTO, SPID_EMAIL_DTO, USERID_DTO } from 'src/dto/property.dto'; -import { checkPgUserDefinedErrors, handlePgError, normalizeKeysToUpperCase, releasePgClient, ResponseStatus } from 'src/utils/helper'; +import { checkPgUserDefinedErrors, handlePgError, normalizeKeysToUpperCase, releasePgClient, ResponseStatus, toUpperCaseKeys } from 'src/utils/helper'; import { PoolClient } from 'pg'; import { PgDBService } from 'src/db/db.service'; @@ -22,48 +22,58 @@ export class UserMaintenanceService { async GetSPUserDetails(body: USERID_DTO): Promise { let client: PoolClient | null = null; - const cursorName = 'p_cursor'; + // Assign unique names to each cursor + const roleCursor = 'role_cursor'; + const menuCursor = 'menu_cursor'; + const menuPageCursor = 'menu_page_cursor'; + const userDetailsCursor = 'user_details_cursor'; try { client = await this.pgDBService.getConnection(); - await client.query('BEGIN'); const callProcQuery = ` - CALL "CARNETSYS".userlogin_pkg_createclientlogins($1, $2, $3, $4, $5) - `; - await client.query(callProcQuery, - [ - body.P_USERID, - cursorName - ]); + CALL "CARNETSYS".spclientuser_pkg_getspuserdetails($1, $2, $3, $4, $5) + `; - // 🚫 DON'T quote the cursor name in FETCH - const fetchResult = await client.query(`FETCH ALL FROM ${cursorName}`); + await client.query(callProcQuery, [ + body.P_USERID, + roleCursor, + menuCursor, + menuPageCursor, + userDetailsCursor + ]); + + // Fetch all data from each cursor + const roleResult = await client.query(`FETCH ALL FROM ${roleCursor}`); + const menuResult = await client.query(`FETCH ALL FROM ${menuCursor}`); + const menuPageResult = await client.query(`FETCH ALL FROM ${menuPageCursor}`); + const userDetailsResult = await client.query(`FETCH ALL FROM ${userDetailsCursor}`); + + // Close all cursors + await client.query(`CLOSE ${roleCursor}`); + await client.query(`CLOSE ${menuCursor}`); + await client.query(`CLOSE ${menuPageCursor}`); + await client.query(`CLOSE ${userDetailsCursor}`); - // 🚫 DON'T quote the cursor name in CLOSE - await client.query(`CLOSE ${cursorName}`); await client.query('COMMIT'); - - checkPgUserDefinedErrors(fetchResult); - - const mailRes = await this.authService.sendMail({ P_TO: body.P_USERID, P_MAIL_TYPE: MailTypeDTO.REGISTER_CLIENT }) - - if (mailRes.statusCode !== 200) { - throw new InternalServerException(); - } + + checkPgUserDefinedErrors(roleResult); + checkPgUserDefinedErrors(menuResult); + checkPgUserDefinedErrors(menuPageResult); + checkPgUserDefinedErrors(userDetailsResult); return { - statusCode: 201, - message: ResponseStatus.clientRegistrationDone, - ...fetchResult?.rows?.[0] || {} + roleDetails: toUpperCaseKeys(roleResult.rows), + menuDetails: toUpperCaseKeys(menuResult.rows), + menuPageDetails: toUpperCaseKeys(menuPageResult.rows), + userDetails: toUpperCaseKeys(userDetailsResult.rows), }; - } catch (error) { if (client) await client.query('ROLLBACK'); - handlePgError(error, UserMaintenanceService.name) + handlePgError(error, 'getSpUserDetails'); } finally { - releasePgClient(client) + releasePgClient(client); } } @@ -100,7 +110,7 @@ export class UserMaintenanceService { return { statusCode: 201, message: ResponseStatus.lockedUserDone, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -138,7 +148,7 @@ export class UserMaintenanceService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -183,7 +193,7 @@ export class UserMaintenanceService { return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -221,7 +231,7 @@ export class UserMaintenanceService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -266,10 +276,16 @@ export class UserMaintenanceService { checkPgUserDefinedErrors(fetchResult); + const mailRes = await this.authService.sendMail({ P_TO: body.P_USERID, P_MAIL_TYPE: MailTypeDTO.REGISTER_SP }) + + if (mailRes.statusCode !== 200) { + throw new InternalServerException(); + } + return { statusCode: 201, message: ResponseStatus.created, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -307,7 +323,7 @@ export class UserMaintenanceService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -341,7 +357,7 @@ export class UserMaintenanceService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); @@ -392,7 +408,7 @@ export class UserMaintenanceService { return { statusCode: 201, message: ResponseStatus.clientRegistrationDone, - ...fetchResult?.rows?.[0] || {} + ...toUpperCaseKeys(fetchResult?.rows)[0] }; } catch (error) { @@ -431,7 +447,7 @@ export class UserMaintenanceService { checkPgUserDefinedErrors(fetchResult); if (fetchResult?.rows.length > 0) { - return [normalizeKeysToUpperCase(fetchResult?.rows[0])] + return [toUpperCaseKeys(fetchResult.rows)[0]] } else { return []; @@ -473,7 +489,7 @@ export class UserMaintenanceService { checkPgUserDefinedErrors(fetchResult); - return fetchResult?.rows ? fetchResult?.rows : [] + return toUpperCaseKeys(fetchResult.rows); } catch (error) { if (client) await client.query('ROLLBACK'); diff --git a/src/utils/helper.ts b/src/utils/helper.ts index da5e6ad..ae328fa 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -28,16 +28,36 @@ export enum ResponseStatus { transmitted = 'Transmitted Successfully', added = 'Added Successfully', deleted = 'Deleted Successfully', + processed = 'Processed Successfully', + voided = 'Voided Successfully', + copied = 'Coppied Successfully', + duplicated = 'Duplicated Successfully', + addl_completed = 'Additional sets completed', + extended = 'Extended Successfully', + saved = 'Saved Successfully', + closed = 'Closed Successfully', + reset_successfull = 'Reset Successfull' } export function normalizeKeysToUpperCase(obj) { - return Object.keys(obj).reduce((acc, key) => { - acc[key.toUpperCase()] = obj[key]; - return acc; - }, {}); + return Object.keys(obj).reduce((acc, key) => { + acc[key.toUpperCase()] = obj[key]; + return acc; + }, {}); } +export function toUpperCaseKeys(rows: Record[]): Record[] { + return rows.map(row => { + const transformedRow: Record = {}; + for (const key in row) { + transformedRow[key.toUpperCase()] = row[key]; + } + return transformedRow; + }); +} + + export const handleError = (error: any, context: string = 'UnknownService'): never => { if (error instanceof BadRequestException || error instanceof BR) {