diff --git a/packages/server-nest/src/modules/Accounts/Accounts.controller.ts b/packages/server-nest/src/modules/Accounts/Accounts.controller.ts index 2d1e7ca4e..5b619d743 100644 --- a/packages/server-nest/src/modules/Accounts/Accounts.controller.ts +++ b/packages/server-nest/src/modules/Accounts/Accounts.controller.ts @@ -13,7 +13,7 @@ import { CreateAccountDTO } from './CreateAccount.dto'; import { EditAccountDTO } from './EditAccount.dto'; import { PublicRoute } from '../Auth/Jwt.guard'; import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types'; -import { ApiOperation, ApiTags } from '@nestjs/swagger'; +import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; // import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types'; // import { ZodValidationPipe } from '@/common/pipes/ZodValidation.pipe'; @@ -25,12 +25,20 @@ export class AccountsController { @Post() @ApiOperation({ summary: 'Create an account' }) + @ApiResponse({ + status: 200, + description: 'The account has been successfully created.', + }) async createAccount(@Body() accountDTO: CreateAccountDTO) { return this.accountsApplication.createAccount(accountDTO); } @Post(':id') @ApiOperation({ summary: 'Edit the given account.' }) + @ApiResponse({ + status: 200, + description: 'The account has been successfully updated.', + }) async editAccount( @Param('id', ParseIntPipe) id: number, @Body() accountDTO: EditAccountDTO, @@ -40,12 +48,20 @@ export class AccountsController { @Delete(':id') @ApiOperation({ summary: 'Delete the given account.' }) + @ApiResponse({ + status: 200, + description: 'The account has been successfully deleted.', + }) async deleteAccount(@Param('id', ParseIntPipe) id: number) { return this.accountsApplication.deleteAccount(id); } @Post(':id/activate') @ApiOperation({ summary: 'Activate the given account.' }) + @ApiResponse({ + status: 200, + description: 'The account has been successfully activated.', + }) async activateAccount(@Param('id', ParseIntPipe) id: number) { return this.accountsApplication.activateAccount(id); } @@ -58,26 +74,41 @@ export class AccountsController { @Get('types') @ApiOperation({ summary: 'Retrieves the account types.' }) + @ApiResponse({ + status: 200, + description: 'The account types have been successfully retrieved.', + }) async getAccountTypes() { return this.accountsApplication.getAccountTypes(); } @Get('transactions') @ApiOperation({ summary: 'Retrieves the account transactions.' }) + @ApiResponse({ + status: 200, + description: 'The account transactions have been successfully retrieved.', + }) async getAccountTransactions(@Query() filter: IAccountsTransactionsFilter) { return this.accountsApplication.getAccountsTransactions(filter); } @Get(':id') @ApiOperation({ summary: 'Retrieves the account details.' }) + @ApiResponse({ + status: 200, + description: 'The account details have been successfully retrieved.', + }) async getAccount(@Param('id', ParseIntPipe) id: number) { return this.accountsApplication.getAccount(id); } @Get() @ApiOperation({ summary: 'Retrieves the accounts.' }) + @ApiResponse({ + status: 200, + description: 'The accounts have been successfully retrieved.', + }) async getAccounts(@Query() filter: IAccountsFilter) { return this.accountsApplication.getAccounts(filter); } - } diff --git a/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.controller.ts b/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.controller.ts index 3dfdb522a..8b251fbfb 100644 --- a/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.controller.ts +++ b/packages/server-nest/src/modules/InventoryAdjutments/InventoryAdjustments.controller.ts @@ -16,7 +16,7 @@ import { import { InventoryAdjustment } from './models/InventoryAdjustment'; import { PublicRoute } from '../Auth/Jwt.guard'; import { IPaginationMeta } from '@/interfaces/Model'; -import { ApiOperation, ApiTags } from '@nestjs/swagger'; +import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('inventory-adjustments') @ApiTags('inventory-adjustments') @@ -28,6 +28,10 @@ export class InventoryAdjustmentsController { @Post('quick') @ApiOperation({ summary: 'Create a quick inventory adjustment.' }) + @ApiResponse({ + status: 200, + description: 'The inventory adjustment has been successfully created.', + }) public async createQuickInventoryAdjustment( @Body() quickAdjustmentDTO: IQuickInventoryAdjustmentDTO, ): Promise { @@ -38,6 +42,10 @@ export class InventoryAdjustmentsController { @Delete(':id') @ApiOperation({ summary: 'Delete the given inventory adjustment.' }) + @ApiResponse({ + status: 200, + description: 'The inventory adjustment has been successfully deleted.', + }) public async deleteInventoryAdjustment( @Param('id') inventoryAdjustmentId: number, ): Promise { @@ -48,6 +56,10 @@ export class InventoryAdjustmentsController { @Get() @ApiOperation({ summary: 'Retrieves the inventory adjustments.' }) + @ApiResponse({ + status: 200, + description: 'The inventory adjustments have been successfully retrieved.', + }) public async getInventoryAdjustments( @Query() filterDTO: IInventoryAdjustmentsFilter, ): Promise<{ @@ -61,6 +73,11 @@ export class InventoryAdjustmentsController { @Get(':id') @ApiOperation({ summary: 'Retrieves the inventory adjustment details.' }) + @ApiResponse({ + status: 200, + description: + 'The inventory adjustment details have been successfully retrieved.', + }) public async getInventoryAdjustment( @Param('id') inventoryAdjustmentId: number, ): Promise { @@ -71,6 +88,10 @@ export class InventoryAdjustmentsController { @Put(':id/publish') @ApiOperation({ summary: 'Publish the given inventory adjustment.' }) + @ApiResponse({ + status: 200, + description: 'The inventory adjustment has been successfully published.', + }) public async publishInventoryAdjustment( @Param('id') inventoryAdjustmentId: number, ): Promise { diff --git a/packages/server-nest/src/modules/InventoryCost/models/InventoryTransaction.ts b/packages/server-nest/src/modules/InventoryCost/models/InventoryTransaction.ts index 15b1e73ef..80a097e86 100644 --- a/packages/server-nest/src/modules/InventoryCost/models/InventoryTransaction.ts +++ b/packages/server-nest/src/modules/InventoryCost/models/InventoryTransaction.ts @@ -118,7 +118,7 @@ export class InventoryTransaction extends TenantBaseModel { // Transaction meta. meta: { relation: Model.HasOneRelation, - modelClass: InventoryTransactionMeta.default, + modelClass: InventoryTransactionMeta, join: { from: 'inventory_transactions.id', to: 'inventory_transaction_meta.inventoryTransactionId', diff --git a/packages/server-nest/src/modules/Items/Item.controller.ts b/packages/server-nest/src/modules/Items/Item.controller.ts index ae1b3f16e..6d0d3c552 100644 --- a/packages/server-nest/src/modules/Items/Item.controller.ts +++ b/packages/server-nest/src/modules/Items/Item.controller.ts @@ -13,7 +13,7 @@ import { TenantController } from '../Tenancy/Tenant.controller'; import { SubscriptionGuard } from '../Subscription/interceptors/Subscription.guard'; import { PublicRoute } from '../Auth/Jwt.guard'; import { ItemsApplicationService } from './ItemsApplication.service'; -import { ApiOperation, ApiTags } from '@nestjs/swagger'; +import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('/items') @UseGuards(SubscriptionGuard) @@ -32,6 +32,10 @@ export class ItemsController extends TenantController { */ @Put(':id') @ApiOperation({ summary: 'Edit the given item (product or service).' }) + @ApiResponse({ + status: 200, + description: 'The item has been successfully updated.', + }) // @UsePipes(new ZodValidationPipe(createItemSchema)) async editItem( @Param('id') id: string, diff --git a/packages/server-nest/src/modules/PaymentReceived/PaymentReceived.application.ts b/packages/server-nest/src/modules/PaymentReceived/PaymentReceived.application.ts index 58172ff2e..13a4de879 100644 --- a/packages/server-nest/src/modules/PaymentReceived/PaymentReceived.application.ts +++ b/packages/server-nest/src/modules/PaymentReceived/PaymentReceived.application.ts @@ -1,24 +1,19 @@ import { IPaymentReceivedCreateDTO, IPaymentReceivedEditDTO, - IPaymentReceivedSmsDetails, IPaymentsReceivedFilter, - // IPaymentsReceivedFilter, - // ISystemUser, - // PaymentReceiveMailOptsDTO, + PaymentReceiveMailOptsDTO, } from './types/PaymentReceived.types'; import { Injectable } from '@nestjs/common'; import { CreatePaymentReceivedService } from './commands/CreatePaymentReceived.serivce'; import { EditPaymentReceivedService } from './commands/EditPaymentReceived.service'; import { DeletePaymentReceivedService } from './commands/DeletePaymentReceived.service'; -// import { GetPaymentReceives } from './queries/GetPaymentsReceived.service'; import { GetPaymentReceivedService } from './queries/GetPaymentReceived.service'; import { GetPaymentReceivedInvoices } from './queries/GetPaymentReceivedInvoices.service'; -// import { PaymentReceiveNotifyBySms } from './PaymentReceivedSmsNotify'; import { GetPaymentReceivedPdfService } from './queries/GetPaymentReceivedPdf.service'; -// import { SendPaymentReceiveMailNotification } from './PaymentReceivedMailNotification'; import { GetPaymentReceivedStateService } from './queries/GetPaymentReceivedState.service'; import { GetPaymentsReceivedService } from './queries/GetPaymentsReceived.service'; +import { SendPaymentReceiveMailNotification } from './commands/PaymentReceivedMailNotification'; @Injectable() export class PaymentReceivesApplication { @@ -29,8 +24,7 @@ export class PaymentReceivesApplication { private getPaymentsReceivedService: GetPaymentsReceivedService, private getPaymentReceivedService: GetPaymentReceivedService, private getPaymentReceiveInvoicesService: GetPaymentReceivedInvoices, - // private paymentSmsNotify: PaymentReceiveNotifyBySms, - // private paymentMailNotify: SendPaymentReceiveMailNotification, + private sendPaymentReceiveMailNotification: SendPaymentReceiveMailNotification, private getPaymentReceivePdfService: GetPaymentReceivedPdfService, private getPaymentReceivedStateService: GetPaymentReceivedStateService, ) {} @@ -103,55 +97,32 @@ export class PaymentReceivesApplication { ); } - /** - * Notify customer via sms about payment receive details. - * @param {number} tenantId - Tenant id. - * @param {number} paymentReceiveid - Payment receive id. - */ - // public notifyPaymentBySms(tenantId: number, paymentReceiveid: number) { - // return this.paymentSmsNotify.notifyBySms(tenantId, paymentReceiveid); - // } - - /** - * Retrieve the SMS details of the given invoice. - * @param {number} tenantId - Tenant id. - * @param {number} paymentReceiveid - Payment receive id. - */ - // public getPaymentSmsDetails = async ( - // tenantId: number, - // paymentReceiveId: number, - // ): Promise => { - // return this.paymentSmsNotify.smsDetails(tenantId, paymentReceiveId); - // }; - /** * Notify customer via mail about payment receive details. - * @param {number} tenantId * @param {number} paymentReceiveId - * @param {IPaymentReceiveMailOpts} messageOpts + * @param {PaymentReceiveMailOptsDTO} messageOpts * @returns {Promise} */ - // public notifyPaymentByMail( - // tenantId: number, - // paymentReceiveId: number, - // messageOpts: PaymentReceiveMailOptsDTO, - // ): Promise { - // return this.paymentMailNotify.triggerMail( - // tenantId, - // paymentReceiveId, - // messageOpts, - // ); - // } + public notifyPaymentByMail( + paymentReceiveId: number, + messageOpts: PaymentReceiveMailOptsDTO, + ): Promise { + return this.sendPaymentReceiveMailNotification.triggerMail( + paymentReceiveId, + messageOpts, + ); + } /** * Retrieves the default mail options of the given payment transaction. - * @param {number} tenantId - * @param {number} paymentReceiveId + * @param {number} paymentReceiveId - Payment receive id. * @returns {Promise} */ - // public getPaymentMailOptions(tenantId: number, paymentReceiveId: number) { - // return this.paymentMailNotify.getMailOptions(tenantId, paymentReceiveId); - // } + public getPaymentMailOptions(paymentReceiveId: number) { + return this.sendPaymentReceiveMailNotification.getMailOptions( + paymentReceiveId, + ); + } /** * Retrieve pdf content of the given payment receive. diff --git a/packages/server-nest/src/modules/PaymentReceived/PaymentsReceived.controller.ts b/packages/server-nest/src/modules/PaymentReceived/PaymentsReceived.controller.ts index 613458662..662c8b225 100644 --- a/packages/server-nest/src/modules/PaymentReceived/PaymentsReceived.controller.ts +++ b/packages/server-nest/src/modules/PaymentReceived/PaymentsReceived.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpCode, Param, ParseIntPipe, Post, @@ -14,9 +15,10 @@ import { IPaymentReceivedCreateDTO, IPaymentReceivedEditDTO, IPaymentsReceivedFilter, + PaymentReceiveMailOptsDTO, } from './types/PaymentReceived.types'; import { PublicRoute } from '../Auth/Jwt.guard'; -import { ApiTags } from '@nestjs/swagger'; +import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('payments-received') @ApiTags('payments-received') @@ -24,7 +26,38 @@ import { ApiTags } from '@nestjs/swagger'; export class PaymentReceivesController { constructor(private paymentReceivesApplication: PaymentReceivesApplication) {} + @Post(':id/mail') + @HttpCode(200) + @ApiResponse({ + status: 200, + description: 'The payment receive mail has been successfully sent.', + }) + public sendPaymentReceiveMail( + @Param('id', ParseIntPipe) paymentReceiveId: number, + @Body() messageOpts: PaymentReceiveMailOptsDTO, + ) { + return this.paymentReceivesApplication.notifyPaymentByMail( + paymentReceiveId, + messageOpts, + ); + } + + @Get(':id/mail') + @ApiResponse({ + status: 200, + description: + 'The payment receive mail options have been successfully retrieved.', + }) + public getPaymentReceiveMailOptions( + @Param('id', ParseIntPipe) paymentReceiveId: number, + ) { + return this.paymentReceivesApplication.getPaymentMailOptions( + paymentReceiveId, + ); + } + @Post() + @ApiOperation({ summary: 'Create a new payment received.' }) public createPaymentReceived( @Body() paymentReceiveDTO: IPaymentReceivedCreateDTO, ) { @@ -34,6 +67,7 @@ export class PaymentReceivesController { } @Put(':id') + @ApiOperation({ summary: 'Edit the given payment received.' }) public editPaymentReceive( @Param('id', ParseIntPipe) paymentReceiveId: number, @Body() paymentReceiveDTO: IPaymentReceivedEditDTO, @@ -45,6 +79,7 @@ export class PaymentReceivesController { } @Delete(':id') + @ApiOperation({ summary: 'Delete the given payment received.' }) public deletePaymentReceive( @Param('id', ParseIntPipe) paymentReceiveId: number, ) { @@ -54,16 +89,27 @@ export class PaymentReceivesController { } @Get() + @ApiOperation({ summary: 'Retrieves the payment received list.' }) public getPaymentsReceived(@Query() filterDTO: IPaymentsReceivedFilter) { return this.paymentReceivesApplication.getPaymentsReceived(filterDTO); } @Get('state') + @ApiOperation({ summary: 'Retrieves the payment received state.' }) + @ApiResponse({ + status: 200, + description: 'The payment received state has been successfully retrieved.', + }) public getPaymentReceivedState() { return this.paymentReceivesApplication.getPaymentReceivedState(); } @Get(':id/invoices') + @ApiOperation({ summary: 'Retrieves the payment received invoices.' }) + @ApiResponse({ + status: 200, + description: 'The payment received invoices have been successfully retrieved.', + }) public getPaymentReceiveInvoices( @Param('id', ParseIntPipe) paymentReceiveId: number, ) { @@ -73,6 +119,11 @@ export class PaymentReceivesController { } @Get(':id') + @ApiOperation({ summary: 'Retrieves the payment received details.' }) + @ApiResponse({ + status: 200, + description: 'The payment received details have been successfully retrieved.', + }) public getPaymentReceive( @Param('id', ParseIntPipe) paymentReceiveId: number, ) { @@ -80,6 +131,11 @@ export class PaymentReceivesController { } @Get(':id/pdf') + @ApiOperation({ summary: 'Retrieves the payment received pdf.' }) + @ApiResponse({ + status: 200, + description: 'The payment received pdf has been successfully retrieved.', + }) public getPaymentReceivePdf( @Param('id', ParseIntPipe) paymentReceivedId: number, ) { diff --git a/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.controller.ts b/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.controller.ts index 13a3e0b2b..eb6614950 100644 --- a/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.controller.ts +++ b/packages/server-nest/src/modules/SaleEstimates/SaleEstimates.controller.ts @@ -1,9 +1,10 @@ -import { ApiOperation, ApiTags } from '@nestjs/swagger'; +import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; import { Body, Controller, Delete, Get, + HttpCode, Param, ParseIntPipe, Post, @@ -32,6 +33,10 @@ export class SaleEstimatesController { @Post() @ApiOperation({ summary: 'Create a new sale estimate.' }) + @ApiResponse({ + status: 200, + description: 'Sale estimate created successfully', + }) public createSaleEstimate( @Body() estimateDTO: ISaleEstimateDTO, ): Promise { @@ -40,6 +45,14 @@ export class SaleEstimatesController { @Put(':id') @ApiOperation({ summary: 'Edit the given sale estimate.' }) + @ApiResponse({ + status: 200, + description: 'Sale estimate edited successfully', + }) + @ApiResponse({ + status: 404, + description: 'Sale estimate not found', + }) public editSaleEstimate( @Param('id', ParseIntPipe) estimateId: number, @Body() estimateDTO: ISaleEstimateDTO, @@ -52,6 +65,14 @@ export class SaleEstimatesController { @Delete(':id') @ApiOperation({ summary: 'Delete the given sale estimate.' }) + @ApiResponse({ + status: 200, + description: 'Sale estimate deleted successfully', + }) + @ApiResponse({ + status: 404, + description: 'Sale estimate not found', + }) public deleteSaleEstimate( @Param('id', ParseIntPipe) estimateId: number, ): Promise { @@ -60,18 +81,30 @@ export class SaleEstimatesController { @Get('state') @ApiOperation({ summary: 'Retrieves the sale estimate state.' }) + @ApiResponse({ + status: 200, + description: 'Sale estimate state retrieved successfully', + }) public getSaleEstimateState() { return this.saleEstimatesApplication.getSaleEstimateState(); } @Get() @ApiOperation({ summary: 'Retrieves the sale estimates.' }) + @ApiResponse({ + status: 200, + description: 'Sale estimates retrieved successfully', + }) public getSaleEstimates(@Query() filterDTO: ISalesEstimatesFilter) { return this.saleEstimatesApplication.getSaleEstimates(filterDTO); } @Post(':id/deliver') @ApiOperation({ summary: 'Deliver the given sale estimate.' }) + @ApiResponse({ + status: 200, + description: 'Sale estimate delivered successfully', + }) public deliverSaleEstimate( @Param('id', ParseIntPipe) saleEstimateId: number, ): Promise { @@ -121,6 +154,7 @@ export class SaleEstimatesController { } @Post(':id/mail') + @HttpCode(200) @ApiOperation({ summary: 'Send the given sale estimate by mail.' }) public sendSaleEstimateMail( @Param('id', ParseIntPipe) saleEstimateId: number, diff --git a/packages/server-nest/src/modules/SaleInvoices/SaleInvoices.controller.ts b/packages/server-nest/src/modules/SaleInvoices/SaleInvoices.controller.ts index 94bb0d88b..75933be09 100644 --- a/packages/server-nest/src/modules/SaleInvoices/SaleInvoices.controller.ts +++ b/packages/server-nest/src/modules/SaleInvoices/SaleInvoices.controller.ts @@ -14,11 +14,13 @@ import { ISaleInvoiceCreateDTO, ISaleInvoiceEditDTO, ISaleInvoiceWriteoffDTO, - InvoiceNotificationType, + ISalesInvoicesFilter, + SaleInvoiceMailState, + SendInvoiceMailDTO, } from './SaleInvoice.types'; import { SaleInvoiceApplication } from './SaleInvoices.application'; import { PublicRoute } from '../Auth/Jwt.guard'; -import { ApiOperation, ApiTags } from '@nestjs/swagger'; +import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger'; @Controller('sale-invoices') @ApiTags('sale-invoices') @@ -28,12 +30,33 @@ export class SaleInvoicesController { @Post() @ApiOperation({ summary: 'Create a new sale invoice.' }) + @ApiResponse({ + status: 201, + description: 'Sale invoice created successfully', + }) createSaleInvoice(@Body() saleInvoiceDTO: ISaleInvoiceCreateDTO) { return this.saleInvoiceApplication.createSaleInvoice(saleInvoiceDTO); } + @Put(':id/mail') + @ApiOperation({ summary: 'Send the sale invoice mail.' }) + @ApiResponse({ + status: 200, + description: 'Sale invoice mail sent successfully', + }) + sendSaleInvoiceMail( + @Param('id', ParseIntPipe) id: number, + @Body() messageDTO: SendInvoiceMailDTO, + ) { + return this.saleInvoiceApplication.sendSaleInvoiceMail(id, messageDTO); + } + @Put(':id') @ApiOperation({ summary: 'Edit the given sale invoice.' }) + @ApiResponse({ + status: 200, + description: 'Sale invoice edited successfully', + }) editSaleInvoice( @Param('id', ParseIntPipe) id: number, @Body() saleInvoiceDTO: ISaleInvoiceEditDTO, @@ -47,10 +70,11 @@ export class SaleInvoicesController { return this.saleInvoiceApplication.deleteSaleInvoice(id); } - // @Get() - // getSaleInvoices(@Query() filterDTO: ISalesInvoicesFilter) { - // return this.saleInvoiceApplication.getSaleInvoices(filterDTO); - // } + @Get() + @ApiOperation({ summary: 'Retrieves the sale invoices.' }) + getSaleInvoices(@Query() filterDTO: ISalesInvoicesFilter) { + return this.saleInvoiceApplication.getSaleInvoices(filterDTO); + } @Get(':id') @ApiOperation({ summary: 'Retrieves the sale invoice details.' }) @@ -111,58 +135,15 @@ export class SaleInvoicesController { return this.saleInvoiceApplication.saleInvoiceHtml(id); } - @Post(':id/notify-sms') - @ApiOperation({ summary: 'Notify the sale invoice by SMS.' }) - notifySaleInvoiceBySms( + @Get(':id/mail-state') + @ApiOperation({ summary: 'Retrieves the sale invoice mail state.' }) + @ApiResponse({ + status: 200, + description: 'Sale invoice mail state retrieved successfully', + }) + getSaleInvoiceMailState( @Param('id', ParseIntPipe) id: number, - @Body('type') notificationType: InvoiceNotificationType, - ) { - // return this.saleInvoiceApplication.notifySaleInvoiceBySms( - // id, - // notificationType, - // ); + ): Promise { + return this.saleInvoiceApplication.getSaleInvoiceMailState(id); } - - // @Post(':id/sms-details') - // getSaleInvoiceSmsDetails( - // @Param('id', ParseIntPipe) id: number, - // @Body() smsDetailsDTO: ISaleInvoiceSmsDetailsDTO, - // ) { - // // return this.saleInvoiceApplication.getSaleInvoiceSmsDetails( - // // id, - // // smsDetailsDTO, - // // ); - // } - - @Get(':id/mail-reminder') - @ApiOperation({ summary: 'Retrieves the sale invoice mail reminder.' }) - getSaleInvoiceMailReminder(@Param('id', ParseIntPipe) id: number) { - // return this.saleInvoiceApplication.getSaleInvoiceMailReminder(tenantId, id); - } - - // @Post(':id/mail-reminder') - // sendSaleInvoiceMailReminder( - // @Param('id', ParseIntPipe) id: number, - // @Body() messageDTO: SendInvoiceMailDTO, - // ) { - // // return this.saleInvoiceApplication.sendSaleInvoiceMailReminder( - // // id, - // // messageDTO, - // // ); - // } - - // @Post(':id/mail') - // sendSaleInvoiceMail( - // @Param('id', ParseIntPipe) id: number, - // @Body() messageDTO: SendInvoiceMailDTO, - // ) { - // // return this.saleInvoiceApplication.sendSaleInvoiceMail(id, messageDTO); - // } - - // @Get(':id/mail-state') - // getSaleInvoiceMailState( - // @Param('id', ParseIntPipe) id: number, - // ): Promise { - // // return this.saleInvoiceApplication.getSaleInvoiceMailState(id); - // } } diff --git a/packages/server-nest/src/modules/SaleReceipts/SaleReceipts.controller.ts b/packages/server-nest/src/modules/SaleReceipts/SaleReceipts.controller.ts index 48d5aaae4..7db4de2d3 100644 --- a/packages/server-nest/src/modules/SaleReceipts/SaleReceipts.controller.ts +++ b/packages/server-nest/src/modules/SaleReceipts/SaleReceipts.controller.ts @@ -3,6 +3,7 @@ import { Controller, Delete, Get, + HttpCode, Param, ParseIntPipe, Post, @@ -25,6 +26,20 @@ export class SaleReceiptsController { return this.saleReceiptApplication.createSaleReceipt(saleReceiptDTO); } + @Put(':id/mail') + @HttpCode(200) + @ApiOperation({ summary: 'Send the sale receipt mail.' }) + sendSaleReceiptMail(@Param('id', ParseIntPipe) id: number) { + return this.saleReceiptApplication.getSaleReceiptMail(id); + } + + @Get(':id/mail') + @HttpCode(200) + @ApiOperation({ summary: 'Retrieves the sale receipt mail.' }) + getSaleReceiptMail(@Param('id', ParseIntPipe) id: number) { + return this.saleReceiptApplication.getSaleReceiptMail(id); + } + @Put(':id') @ApiOperation({ summary: 'Edit the given sale receipt.' }) editSaleReceipt( diff --git a/packages/server-nest/src/modules/SaleReceipts/commands/SaleReceiptMailNotification.ts b/packages/server-nest/src/modules/SaleReceipts/commands/SaleReceiptMailNotification.ts index 24d4dd7f4..fe064ef18 100644 --- a/packages/server-nest/src/modules/SaleReceipts/commands/SaleReceiptMailNotification.ts +++ b/packages/server-nest/src/modules/SaleReceipts/commands/SaleReceiptMailNotification.ts @@ -4,7 +4,7 @@ import { } from '../constants'; import { mergeAndValidateMailOptions } from '@/modules/MailNotification/utils'; import { transformReceiptToMailDataArgs } from '../utils'; -import { Injectable } from '@nestjs/common'; +import { Inject, Injectable } from '@nestjs/common'; import { GetSaleReceipt } from '../queries/GetSaleReceipt.service'; import { SaleReceiptsPdfService } from '../queries/SaleReceiptsPdf.service'; import { ContactMailNotification } from '@/modules/MailNotification/ContactMailNotification'; @@ -34,6 +34,9 @@ export class SaleReceiptMailNotification { private readonly contactMailNotification: ContactMailNotification, private readonly eventEmitter: EventEmitter2, private readonly mailTransporter: MailTransporter, + + @Inject(SaleReceipt.name) + private readonly saleReceiptModel: typeof SaleReceipt ) {} /** @@ -67,7 +70,7 @@ export class SaleReceiptMailNotification { public async getMailOptions( saleReceiptId: number, ): Promise { - const saleReceipt = await SaleReceipt.query() + const saleReceipt = await this.saleReceiptModel.query() .findById(saleReceiptId) .throwIfNotFound(); diff --git a/packages/server-nest/test/payment-received.e2e-spec.ts b/packages/server-nest/test/payment-received.e2e-spec.ts index 53e6a3668..db6d07156 100644 --- a/packages/server-nest/test/payment-received.e2e-spec.ts +++ b/packages/server-nest/test/payment-received.e2e-spec.ts @@ -129,4 +129,37 @@ describe('Payment Received (e2e)', () => { .set('organization-id', orgainzationId) .expect(200); }); + + it('/payments-received/:id/mail (POST)', async () => { + const response = await request(app.getHttpServer()) + .post('/payments-received') + .set('organization-id', orgainzationId) + .send(requestPaymentReceivedBody(invoice.id)); + + const paymentReceivedId = response.body.id; + + return request(app.getHttpServer()) + .post(`/payments-received/${paymentReceivedId}/mail`) + .set('organization-id', orgainzationId) + .send({ + subject: 'Email subject from here', + to: 'a.bouhuolia@gmail.com', + body: 'asfdasdf', + }) + .expect(200); + }); + + it('/payments-received/:id/mail (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/payments-received') + .set('organization-id', orgainzationId) + .send(requestPaymentReceivedBody(invoice.id)); + + const paymentReceivedId = response.body.id; + + return request(app.getHttpServer()) + .get(`/payments-received/${paymentReceivedId}/mail`) + .set('organization-id', orgainzationId) + .expect(200); + }); }); diff --git a/packages/server-nest/test/sale-estimates.e2e-spec.ts b/packages/server-nest/test/sale-estimates.e2e-spec.ts index 4ef85800b..4bd07b51c 100644 --- a/packages/server-nest/test/sale-estimates.e2e-spec.ts +++ b/packages/server-nest/test/sale-estimates.e2e-spec.ts @@ -119,4 +119,41 @@ describe('Sale Estimates (e2e)', () => { .set('organization-id', orgainzationId) .expect(200); }); + + it('/sale-estimates (GET)', async () => { + return request(app.getHttpServer()) + .get('/sale-estimates') + .set('organization-id', orgainzationId) + .expect(200); + }); + + it('/sale-estimates/:id/mail (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/sale-estimates') + .set('organization-id', orgainzationId) + .send(makeEstimateRequest()); + + return request(app.getHttpServer()) + .get(`/sale-estimates/${response.body.id}/mail`) + .set('organization-id', orgainzationId) + .expect(200); + }); + + it('/sale-estimates/:id/mail (POST)', async () => { + const response = await request(app.getHttpServer()) + .post('/sale-estimates') + .set('organization-id', orgainzationId) + .send(makeEstimateRequest()); + + return request(app.getHttpServer()) + .post(`/sale-estimates/${response.body.id}/mail`) + .set('organization-id', orgainzationId) + .send({ + subject: 'Email subject from here', + to: 'a.bouhuolia@gmail.com', + body: 'asfdasdf', + attachInvoice: false, + }) + .expect(200); + }); }); diff --git a/packages/server-nest/test/sale-invoices.e2e-spec.ts b/packages/server-nest/test/sale-invoices.e2e-spec.ts index 4c2d3a33b..7deffafe5 100644 --- a/packages/server-nest/test/sale-invoices.e2e-spec.ts +++ b/packages/server-nest/test/sale-invoices.e2e-spec.ts @@ -84,6 +84,18 @@ describe('Sale Invoices (e2e)', () => { .expect(200); }); + it('/sale-invoices (GET)', async () => { + await request(app.getHttpServer()) + .post('/sale-invoices') + .set('organization-id', orgainzationId) + .send(requestSaleInvoiceBody()); + + return request(app.getHttpServer()) + .get('/sale-invoices') + .set('organization-id', orgainzationId) + .expect(200); + }); + it('/sale-invoices/:id (GET)', async () => { const response = await request(app.getHttpServer()) .post('/sale-invoices') @@ -172,4 +184,34 @@ describe('Sale Invoices (e2e)', () => { .set('organization-id', orgainzationId) .expect(200); }); + + it('/sale-invoices/:id/mail-state (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/sale-invoices') + .set('organization-id', orgainzationId) + .send(requestSaleInvoiceBody()); + + return request(app.getHttpServer()) + .get(`/sale-invoices/${response.body.id}/mail-state`) + .set('organization-id', orgainzationId) + .expect(200); + }); + + it('/sale-invoices/:id/mail (POST)', async () => { + const response = await request(app.getHttpServer()) + .post('/sale-invoices') + .set('organization-id', orgainzationId) + .send(requestSaleInvoiceBody()); + + return request(app.getHttpServer()) + .put(`/sale-invoices/${response.body.id}/mail`) + .set('organization-id', orgainzationId) + .send({ + subject: 'Email subject from here', + to: 'a.bouhuolia@gmail.com', + body: 'asfdasdf', + attachInvoice: false, + }) + .expect(200); + }); }); diff --git a/packages/server-nest/test/sale-receipts.e2e-spec.ts b/packages/server-nest/test/sale-receipts.e2e-spec.ts index 4784c6a9f..0f6bbd33a 100644 --- a/packages/server-nest/test/sale-receipts.e2e-spec.ts +++ b/packages/server-nest/test/sale-receipts.e2e-spec.ts @@ -90,6 +90,13 @@ describe('Sale Receipts (e2e)', () => { .expect(200); }); + it('/sale-receipts (GET)', async () => { + return request(app.getHttpServer()) + .get('/sale-receipts') + .set('organization-id', orgainzationId) + .expect(200); + }); + it('/sale-receipts/:id (GET)', async () => { const response = await request(app.getHttpServer()) .post('/sale-receipts') @@ -103,4 +110,16 @@ describe('Sale Receipts (e2e)', () => { .set('organization-id', orgainzationId) .expect(200); }); + + it('/sale-receipts/:id/mail (GET)', async () => { + const response = await request(app.getHttpServer()) + .post('/sale-receipts') + .set('organization-id', orgainzationId) + .send(makeReceiptRequest()); + + return request(app.getHttpServer()) + .get(`/sale-receipts/${response.body.id}/mail`) + .set('organization-id', orgainzationId) + .expect(200); + }); });