From aaf2764a7e2f35a86e5f59a85d1788944cc7b5ab Mon Sep 17 00:00:00 2001 From: Kallesh B S Date: Wed, 9 Jul 2025 15:53:49 +0530 Subject: [PATCH] new api in carnet application and modification --- src/auth/auth.service.ts | 4 +- src/dto/manage-clients/manage-clients.dto.ts | 4 + src/mail/mail.module.ts | 44 ++--- .../carnet-application.controller.ts | 20 ++- .../carnet-application.service.ts | 167 ++++++++++++++++-- .../manage-clients.controller.ts | 6 + .../manage-clients/manage-clients.service.ts | 38 ++++ .../manage-holders/manage-holders.service.ts | 2 +- 8 files changed, 244 insertions(+), 41 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 2f621a1..23b55d8 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -708,7 +708,7 @@ export class AuthService { template: 'a', context: { to: body.P_TO, - url: `https://client.alphaomegainfosys.com/register/${token}` + url: `https://client.alphaomegainfosys.com/register` } } case MailTypeDTO.FORGOT_PASSWORD: @@ -847,8 +847,6 @@ export class AuthService { token = await this.generateToken({ P_TO: body.P_TO, uuid: uuid }) - - const mailTemplate: MailTemplateDTO | null = await this.getMailTemplate(body, token, ROLE); if (!mailTemplate) { diff --git a/src/dto/manage-clients/manage-clients.dto.ts b/src/dto/manage-clients/manage-clients.dto.ts index e1d494f..8ac52e5 100644 --- a/src/dto/manage-clients/manage-clients.dto.ts +++ b/src/dto/manage-clients/manage-clients.dto.ts @@ -120,6 +120,10 @@ export class GetClientDTO extends IntersectionType( CLIENTID_DTO ) { } +export class GetClientContactByLacationIdDTO extends IntersectionType( + SPID_DTO, LOCATIONID_DTO +){} + export class ClientContactControlsDTO extends IntersectionType( SPID_DTO, CLIENT_CONTACTID_DTO, diff --git a/src/mail/mail.module.ts b/src/mail/mail.module.ts index f763726..e33cbb9 100644 --- a/src/mail/mail.module.ts +++ b/src/mail/mail.module.ts @@ -17,28 +17,32 @@ import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handleba MailerModule.forRootAsync({ imports: [ConfigModule], - useFactory: (configService: ConfigService) => ({ - transport: { - host: 'smtp.gmail.com', - port: 587, - // ignoreTLS: true, - secure: false, - auth: { - user: configService.get('MAIL_USER'), - pass: configService.get('MAIL_PASS'), + useFactory: (configService: ConfigService) => { + const templatePath = join(__dirname, '../../..', 'public', 'mail-templates'); + console.log('Resolved mail template path:', templatePath); + + return { + transport: { + host: 'smtp.gmail.com', + port: 587, + secure: false, + auth: { + user: configService.get('MAIL_USER'), + pass: configService.get('MAIL_PASS'), + }, }, - }, - defaults: { - from: `"Carnet APP" <${configService.get('MAIL_USER')}>`, - }, - template: { - dir: join(__dirname, '../../..', 'public', 'mail-templates'), - adapter: new HandlebarsAdapter(), // import from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter' - options: { - strict: true, + defaults: { + from: `"Carnet APP" <${configService.get('MAIL_USER')}>`, }, - }, - }), + template: { + dir: templatePath, + adapter: new HandlebarsAdapter(), + options: { + strict: true, + }, + }, + }; + }, inject: [ConfigService], }), ], diff --git a/src/oracle/carnet-application/carnet-application.controller.ts b/src/oracle/carnet-application/carnet-application.controller.ts index e777186..0301c1a 100644 --- a/src/oracle/carnet-application/carnet-application.controller.ts +++ b/src/oracle/carnet-application/carnet-application.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Param, Patch, Post, Put, UseGuards } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Param, Patch, Post, Put, UseGuards } from '@nestjs/common'; import { CarnetApplicationService } from './carnet-application.service'; import { ApiTags } from '@nestjs/swagger'; @@ -63,6 +63,16 @@ export class CarnetApplicationController { return this.carnetApplicationService.AddCountries(body); } + @Put('EditGenerallistItems') + EditGenerallistItems(@Body() body: AddGenerallistItemsDTO) { + return this.carnetApplicationService.EditGenerallistItems(body); + } + + @Delete('DeleteGenerallistItems') + DeleteGenerallistItems() { + return this.carnetApplicationService.DeleteGenerallistItems(); + } + @Patch('UpdateShippingDetails') UpdateShippingDetails(@Body() body: UpdateShippingDetailsDTO) { return this.carnetApplicationService.UpdateShippingDetails(body); @@ -110,11 +120,19 @@ export class CarnetApplicationController { return this.carnetApplicationService.GetGoodsDetailstoEdit(body); } + @Get('GetGoodsItemstoEdit/:P_SPID/:P_USERID/:P_HEADERID') + GetGoodsItemstoEdit(@Param() body: GetCarnetControlCenterDTO) { + return this.carnetApplicationService.GetGoodsItemstoEdit(body); + } + @Get('GetCountryDetailstoEdit/:P_SPID/:P_USERID/:P_HEADERID') GetCountryDetailstoEdit(@Param() body: GetCarnetControlCenterDTO) { return this.carnetApplicationService.GetCountryDetailstoEdit(body); } + + + @Get('GetShipPaymentDetailstoEdit/:P_SPID/:P_USERID/:P_HEADERID') GetShipPaymentDetailstoEdit(@Param() body: GetCarnetControlCenterDTO) { return this.carnetApplicationService.GetShipPaymentDetailstoEdit(body); diff --git a/src/oracle/carnet-application/carnet-application.service.ts b/src/oracle/carnet-application/carnet-application.service.ts index 155eea8..c98f56f 100644 --- a/src/oracle/carnet-application/carnet-application.service.ts +++ b/src/oracle/carnet-application/carnet-application.service.ts @@ -219,7 +219,14 @@ export class CarnetApplicationService { throw new InternalServerException("Incomplete data received from the database."); } - return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + 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 { @@ -256,7 +263,14 @@ export class CarnetApplicationService { throw new InternalServerException("Incomplete data received from the database."); } - return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + 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: "Transmitted Successfully", ...fres[0] }; } catch (error) { handleError(error, CarnetApplicationService.name) } finally { @@ -340,7 +354,15 @@ export class CarnetApplicationService { throw new InternalServerException("Incomplete data received from the database."); } - return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); + // return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); + const fres: any = await fetchCursor(outBinds.P_ERRORMESG, 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: "Updated Successfully", ...fres[0] }; } catch (error) { handleError(error, CarnetApplicationService.name) } finally { @@ -383,7 +405,14 @@ export class CarnetApplicationService { throw new InternalServerException("Incomplete data received from the database."); } - return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); + const fres: any = await fetchCursor(outBinds.P_ERRORMESG, 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: "Updated Successfully", ...fres[0] }; } catch (error) { handleError(error, CarnetApplicationService.name) } finally { @@ -423,7 +452,15 @@ export class CarnetApplicationService { throw new InternalServerException("Incomplete data received from the database."); } - return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); + // return await fetchCursor(outBinds.P_ERRORMESG, CarnetApplicationService.name); + const fres: any = await fetchCursor(outBinds.P_ERRORMESG, 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: "Added Successfully", ...fres[0] }; } catch (error) { handleError(error, CarnetApplicationService.name) } finally { @@ -431,6 +468,55 @@ export class CarnetApplicationService { } } + async EditGenerallistItems(body: AddGenerallistItemsDTO) { + let connection; + try { + connection = await this.oracleDBService.getConnection(); + + const GLTABLE_INSTANCE = await this.oracleService.get_GL_TABLE_INSTANCE(body); + + const result = await connection.execute( + `BEGIN + CARNETAPPLICATION_PKG.EditGenerallistItems( + :P_HEADERID, :P_GLTABLE, :P_USERID, :P_CURSOR + ); + END;`, + { + P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, + P_GLTABLE: { val: GLTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }, + // P_GLTABLE: { val: GLTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + // P_ERRORMESG: { 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: "Updated Successfully", ...fres[0] }; + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + + async DeleteGenerallistItems() { } + async AddCountries(body: AddCountriesDTO) { let connection; try { @@ -441,7 +527,7 @@ export class CarnetApplicationService { const result = await connection.execute( `BEGIN CARNETAPPLICATION_PKG.AddCountries( - :P_HEADERID, :P_USSETS, :P_COUNTRYTABLE, :P_USERID, :P_ERRORMESG + :P_HEADERID, :P_USSETS, :P_COUNTRYTABLE, :P_USERID, :P_CURSOR ); END;`, { @@ -451,8 +537,8 @@ export class CarnetApplicationService { // P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: 'CARNETSYS.GLTABLE' }, // P_COUNTRYTABLE: { val: COUNTRYTABLE_INSTANCE, type: oracledb.DB_TYPE_OBJECT }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, - P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, - // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + // P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); @@ -460,12 +546,19 @@ export class CarnetApplicationService { await connection.commit(); const outBinds = result.outBinds; - if (!outBinds?.P_ERRORMESG) { + 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_ERRORMESG, CarnetApplicationService.name); + 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: "Added Successfully", ...fres[0] }; } catch (error) { handleError(error, CarnetApplicationService.name) } finally { @@ -480,10 +573,10 @@ export class CarnetApplicationService { const result = await connection.execute( `BEGIN - CARNETAPPLICATION_PKG.UpdateHolder( + CARNETAPPLICATION_PKG.UpdateShippingDetails( :P_HEADERID, :P_SHIPTOTYPE, :P_SHIPADDRID, :P_FORMOFSECURITY, :P_INSPROTECTION, :P_LDIPROTECTION, :P_DELIVERYTYPE, :P_DELIVERYMETHOD, :P_PAYMENTMETHOD, - :P_CUSTCOURIERNO, :P_REFNO, :P_NOTES, :P_USERID, :P_ERRORMESG + :P_CUSTCOURIERNO, :P_REFNO, :P_NOTES, :P_USERID, :P_CURSOR ); END;`, { @@ -500,8 +593,8 @@ export class CarnetApplicationService { P_REFNO: { val: body.P_REFNO, type: oracledb.DB_TYPE_NVARCHAR }, P_NOTES: { val: body.P_NOTES, type: oracledb.DB_TYPE_NVARCHAR }, P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, - P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, - // P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + // P_ERRORMESG: { dir: oracledb.BIND_OUT, type: oracledb.CURSOR }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } }, { outFormat: oracledb.OUT_FORMAT_OBJECT } ); @@ -509,12 +602,19 @@ export class CarnetApplicationService { await connection.commit(); const outBinds = result.outBinds; - if (!outBinds?.P_ERRORMESG) { + 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_ERRORMESG, CarnetApplicationService.name); + 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: "Updated Successfully", ...fres[0] }; } catch (error) { handleError(error, CarnetApplicationService.name) } finally { @@ -840,4 +940,39 @@ export class CarnetApplicationService { await closeOracleDbConnection(connection, CarnetApplicationService.name) } } + async GetGoodsItemstoEdit(body: GetCarnetControlCenterDTO) { + let connection; + + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + CARNETCONTROLCENTER_PKG.GetGoodsItemstoEdit( + :P_SPID, :P_USERID , :P_HEADERID, :P_CURSOR + ); + END;`, + { + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_USERID: { val: body.P_USERID, type: oracledb.DB_TYPE_NVARCHAR }, + P_HEADERID: { val: body.P_HEADERID, type: oracledb.DB_TYPE_NUMBER }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + }, + { outFormat: oracledb.OUT_FORMAT_OBJECT } + ); + + const outBinds = result.outBinds; + if (!outBinds?.P_CURSOR) { + this.logger.error('One or more expected cursors are missing from stored procedure output.'); + throw new InternalServerException("Incomplete data received from the database."); + } + + return await fetchCursor(outBinds.P_CURSOR, CarnetApplicationService.name); + } catch (error) { + handleError(error, CarnetApplicationService.name) + } finally { + await closeOracleDbConnection(connection, CarnetApplicationService.name) + } + } + } diff --git a/src/oracle/manage-clients/manage-clients.controller.ts b/src/oracle/manage-clients/manage-clients.controller.ts index f8f70c6..c146f8d 100644 --- a/src/oracle/manage-clients/manage-clients.controller.ts +++ b/src/oracle/manage-clients/manage-clients.controller.ts @@ -6,6 +6,7 @@ import { ClientContactControlsDTO, CreateClientContactsDTO, CreateClientDataDTO, CreateClientLocationsDTO, + GetClientContactByLacationIdDTO, GetClientDTO, GetPreparersParamDTO, GetPreparersQueryDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO } from 'src/dto/property.dto'; @@ -81,6 +82,11 @@ export class ManageClientsController { return this.manageClientsService.GetPreparerContactsByClientid(body); } + @Get('GetPreparerContactsbyClientLocationID/:P_SPID/:P_LOCATIONID') + GetPreparerContactsbyClientLocationID(@Param() body: GetClientContactByLacationIdDTO) { + return this.manageClientsService.GetPreparerContactsbyClientLocationID(body); + } + @Get('GetPreparerLocByClientid/:P_SPID/:P_CLIENTID') GetPreparerLocByClientid(@Param() body: GetClientDTO) { return this.manageClientsService.GetPreparerLocByClientid(body); diff --git a/src/oracle/manage-clients/manage-clients.service.ts b/src/oracle/manage-clients/manage-clients.service.ts index 654a088..15674d8 100644 --- a/src/oracle/manage-clients/manage-clients.service.ts +++ b/src/oracle/manage-clients/manage-clients.service.ts @@ -10,6 +10,7 @@ import { ClientContactControlsDTO, CreateClientContactsDTO, CreateClientDataDTO, CreateClientLocationsDTO, + GetClientContactByLacationIdDTO, GetClientDTO, GetPreparersDTO, UpdateClientContactsDTO, UpdateClientDTO, UpdateClientLocationsDTO, } from 'src/dto/property.dto'; @@ -718,6 +719,43 @@ export class ManageClientsService { } }; + GetPreparerContactsbyClientLocationID = async (body: GetClientContactByLacationIdDTO) => { + let connection; + + try { + connection = await this.oracleDBService.getConnection(); + + const result = await connection.execute( + `BEGIN + MANAGEPREPARER_PKG.GetPreparerContactsByClientid( + :P_SPID, :P_LOCATIONID, :P_CURSOR + ); + END;`, + { + P_SPID: { val: body.P_SPID, type: oracledb.DB_TYPE_NUMBER }, + P_LOCATIONID: { val: body.P_LOCATIONID, type: oracledb.DB_TYPE_NUMBER }, + P_CURSOR: { type: oracledb.CURSOR, dir: oracledb.BIND_OUT } + }, + { + outFormat: oracledb.OUT_FORMAT_OBJECT, + }, + ); + + const outBinds: any = 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, ManageClientsService.name); + + } catch (error) { + handleError(error, ManageClientsService.name) + } finally { + await closeOracleDbConnection(connection, ManageClientsService.name) + } + } + GetPreparerLocByClientid = async (body: GetClientDTO) => { let connection; diff --git a/src/oracle/manage-holders/manage-holders.service.ts b/src/oracle/manage-holders/manage-holders.service.ts index ab55155..ec4821b 100644 --- a/src/oracle/manage-holders/manage-holders.service.ts +++ b/src/oracle/manage-holders/manage-holders.service.ts @@ -485,7 +485,7 @@ export class ManageHoldersService { throw new BadRequestException(fres[0].ERRORMESG) } - return { statusCode: 200, message: 'Reactivated holder successfully' }; + return { statusCode: 200, message: 'Inactivated holder successfully' }; } catch (error) { handleError(error, ManageHoldersService.name) } finally {