refactor: e2e test cases

This commit is contained in:
Ahmed Bouhuolia
2025-01-15 17:02:42 +02:00
parent 271c46ea3b
commit 108d286f62
14 changed files with 362 additions and 115 deletions

View File

@@ -13,7 +13,7 @@ import { CreateAccountDTO } from './CreateAccount.dto';
import { EditAccountDTO } from './EditAccount.dto'; import { EditAccountDTO } from './EditAccount.dto';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types'; 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 { IAccountsFilter, IAccountsTransactionsFilter } from './Accounts.types';
// import { ZodValidationPipe } from '@/common/pipes/ZodValidation.pipe'; // import { ZodValidationPipe } from '@/common/pipes/ZodValidation.pipe';
@@ -25,12 +25,20 @@ export class AccountsController {
@Post() @Post()
@ApiOperation({ summary: 'Create an account' }) @ApiOperation({ summary: 'Create an account' })
@ApiResponse({
status: 200,
description: 'The account has been successfully created.',
})
async createAccount(@Body() accountDTO: CreateAccountDTO) { async createAccount(@Body() accountDTO: CreateAccountDTO) {
return this.accountsApplication.createAccount(accountDTO); return this.accountsApplication.createAccount(accountDTO);
} }
@Post(':id') @Post(':id')
@ApiOperation({ summary: 'Edit the given account.' }) @ApiOperation({ summary: 'Edit the given account.' })
@ApiResponse({
status: 200,
description: 'The account has been successfully updated.',
})
async editAccount( async editAccount(
@Param('id', ParseIntPipe) id: number, @Param('id', ParseIntPipe) id: number,
@Body() accountDTO: EditAccountDTO, @Body() accountDTO: EditAccountDTO,
@@ -40,12 +48,20 @@ export class AccountsController {
@Delete(':id') @Delete(':id')
@ApiOperation({ summary: 'Delete the given account.' }) @ApiOperation({ summary: 'Delete the given account.' })
@ApiResponse({
status: 200,
description: 'The account has been successfully deleted.',
})
async deleteAccount(@Param('id', ParseIntPipe) id: number) { async deleteAccount(@Param('id', ParseIntPipe) id: number) {
return this.accountsApplication.deleteAccount(id); return this.accountsApplication.deleteAccount(id);
} }
@Post(':id/activate') @Post(':id/activate')
@ApiOperation({ summary: 'Activate the given account.' }) @ApiOperation({ summary: 'Activate the given account.' })
@ApiResponse({
status: 200,
description: 'The account has been successfully activated.',
})
async activateAccount(@Param('id', ParseIntPipe) id: number) { async activateAccount(@Param('id', ParseIntPipe) id: number) {
return this.accountsApplication.activateAccount(id); return this.accountsApplication.activateAccount(id);
} }
@@ -58,26 +74,41 @@ export class AccountsController {
@Get('types') @Get('types')
@ApiOperation({ summary: 'Retrieves the account types.' }) @ApiOperation({ summary: 'Retrieves the account types.' })
@ApiResponse({
status: 200,
description: 'The account types have been successfully retrieved.',
})
async getAccountTypes() { async getAccountTypes() {
return this.accountsApplication.getAccountTypes(); return this.accountsApplication.getAccountTypes();
} }
@Get('transactions') @Get('transactions')
@ApiOperation({ summary: 'Retrieves the account transactions.' }) @ApiOperation({ summary: 'Retrieves the account transactions.' })
@ApiResponse({
status: 200,
description: 'The account transactions have been successfully retrieved.',
})
async getAccountTransactions(@Query() filter: IAccountsTransactionsFilter) { async getAccountTransactions(@Query() filter: IAccountsTransactionsFilter) {
return this.accountsApplication.getAccountsTransactions(filter); return this.accountsApplication.getAccountsTransactions(filter);
} }
@Get(':id') @Get(':id')
@ApiOperation({ summary: 'Retrieves the account details.' }) @ApiOperation({ summary: 'Retrieves the account details.' })
@ApiResponse({
status: 200,
description: 'The account details have been successfully retrieved.',
})
async getAccount(@Param('id', ParseIntPipe) id: number) { async getAccount(@Param('id', ParseIntPipe) id: number) {
return this.accountsApplication.getAccount(id); return this.accountsApplication.getAccount(id);
} }
@Get() @Get()
@ApiOperation({ summary: 'Retrieves the accounts.' }) @ApiOperation({ summary: 'Retrieves the accounts.' })
@ApiResponse({
status: 200,
description: 'The accounts have been successfully retrieved.',
})
async getAccounts(@Query() filter: IAccountsFilter) { async getAccounts(@Query() filter: IAccountsFilter) {
return this.accountsApplication.getAccounts(filter); return this.accountsApplication.getAccounts(filter);
} }
} }

View File

@@ -16,7 +16,7 @@ import {
import { InventoryAdjustment } from './models/InventoryAdjustment'; import { InventoryAdjustment } from './models/InventoryAdjustment';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { IPaginationMeta } from '@/interfaces/Model'; import { IPaginationMeta } from '@/interfaces/Model';
import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
@Controller('inventory-adjustments') @Controller('inventory-adjustments')
@ApiTags('inventory-adjustments') @ApiTags('inventory-adjustments')
@@ -28,6 +28,10 @@ export class InventoryAdjustmentsController {
@Post('quick') @Post('quick')
@ApiOperation({ summary: 'Create a quick inventory adjustment.' }) @ApiOperation({ summary: 'Create a quick inventory adjustment.' })
@ApiResponse({
status: 200,
description: 'The inventory adjustment has been successfully created.',
})
public async createQuickInventoryAdjustment( public async createQuickInventoryAdjustment(
@Body() quickAdjustmentDTO: IQuickInventoryAdjustmentDTO, @Body() quickAdjustmentDTO: IQuickInventoryAdjustmentDTO,
): Promise<InventoryAdjustment> { ): Promise<InventoryAdjustment> {
@@ -38,6 +42,10 @@ export class InventoryAdjustmentsController {
@Delete(':id') @Delete(':id')
@ApiOperation({ summary: 'Delete the given inventory adjustment.' }) @ApiOperation({ summary: 'Delete the given inventory adjustment.' })
@ApiResponse({
status: 200,
description: 'The inventory adjustment has been successfully deleted.',
})
public async deleteInventoryAdjustment( public async deleteInventoryAdjustment(
@Param('id') inventoryAdjustmentId: number, @Param('id') inventoryAdjustmentId: number,
): Promise<void> { ): Promise<void> {
@@ -48,6 +56,10 @@ export class InventoryAdjustmentsController {
@Get() @Get()
@ApiOperation({ summary: 'Retrieves the inventory adjustments.' }) @ApiOperation({ summary: 'Retrieves the inventory adjustments.' })
@ApiResponse({
status: 200,
description: 'The inventory adjustments have been successfully retrieved.',
})
public async getInventoryAdjustments( public async getInventoryAdjustments(
@Query() filterDTO: IInventoryAdjustmentsFilter, @Query() filterDTO: IInventoryAdjustmentsFilter,
): Promise<{ ): Promise<{
@@ -61,6 +73,11 @@ export class InventoryAdjustmentsController {
@Get(':id') @Get(':id')
@ApiOperation({ summary: 'Retrieves the inventory adjustment details.' }) @ApiOperation({ summary: 'Retrieves the inventory adjustment details.' })
@ApiResponse({
status: 200,
description:
'The inventory adjustment details have been successfully retrieved.',
})
public async getInventoryAdjustment( public async getInventoryAdjustment(
@Param('id') inventoryAdjustmentId: number, @Param('id') inventoryAdjustmentId: number,
): Promise<InventoryAdjustment> { ): Promise<InventoryAdjustment> {
@@ -71,6 +88,10 @@ export class InventoryAdjustmentsController {
@Put(':id/publish') @Put(':id/publish')
@ApiOperation({ summary: 'Publish the given inventory adjustment.' }) @ApiOperation({ summary: 'Publish the given inventory adjustment.' })
@ApiResponse({
status: 200,
description: 'The inventory adjustment has been successfully published.',
})
public async publishInventoryAdjustment( public async publishInventoryAdjustment(
@Param('id') inventoryAdjustmentId: number, @Param('id') inventoryAdjustmentId: number,
): Promise<void> { ): Promise<void> {

View File

@@ -118,7 +118,7 @@ export class InventoryTransaction extends TenantBaseModel {
// Transaction meta. // Transaction meta.
meta: { meta: {
relation: Model.HasOneRelation, relation: Model.HasOneRelation,
modelClass: InventoryTransactionMeta.default, modelClass: InventoryTransactionMeta,
join: { join: {
from: 'inventory_transactions.id', from: 'inventory_transactions.id',
to: 'inventory_transaction_meta.inventoryTransactionId', to: 'inventory_transaction_meta.inventoryTransactionId',

View File

@@ -13,7 +13,7 @@ import { TenantController } from '../Tenancy/Tenant.controller';
import { SubscriptionGuard } from '../Subscription/interceptors/Subscription.guard'; import { SubscriptionGuard } from '../Subscription/interceptors/Subscription.guard';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { ItemsApplicationService } from './ItemsApplication.service'; import { ItemsApplicationService } from './ItemsApplication.service';
import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
@Controller('/items') @Controller('/items')
@UseGuards(SubscriptionGuard) @UseGuards(SubscriptionGuard)
@@ -32,6 +32,10 @@ export class ItemsController extends TenantController {
*/ */
@Put(':id') @Put(':id')
@ApiOperation({ summary: 'Edit the given item (product or service).' }) @ApiOperation({ summary: 'Edit the given item (product or service).' })
@ApiResponse({
status: 200,
description: 'The item has been successfully updated.',
})
// @UsePipes(new ZodValidationPipe(createItemSchema)) // @UsePipes(new ZodValidationPipe(createItemSchema))
async editItem( async editItem(
@Param('id') id: string, @Param('id') id: string,

View File

@@ -1,24 +1,19 @@
import { import {
IPaymentReceivedCreateDTO, IPaymentReceivedCreateDTO,
IPaymentReceivedEditDTO, IPaymentReceivedEditDTO,
IPaymentReceivedSmsDetails,
IPaymentsReceivedFilter, IPaymentsReceivedFilter,
// IPaymentsReceivedFilter, PaymentReceiveMailOptsDTO,
// ISystemUser,
// PaymentReceiveMailOptsDTO,
} from './types/PaymentReceived.types'; } from './types/PaymentReceived.types';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { CreatePaymentReceivedService } from './commands/CreatePaymentReceived.serivce'; import { CreatePaymentReceivedService } from './commands/CreatePaymentReceived.serivce';
import { EditPaymentReceivedService } from './commands/EditPaymentReceived.service'; import { EditPaymentReceivedService } from './commands/EditPaymentReceived.service';
import { DeletePaymentReceivedService } from './commands/DeletePaymentReceived.service'; import { DeletePaymentReceivedService } from './commands/DeletePaymentReceived.service';
// import { GetPaymentReceives } from './queries/GetPaymentsReceived.service';
import { GetPaymentReceivedService } from './queries/GetPaymentReceived.service'; import { GetPaymentReceivedService } from './queries/GetPaymentReceived.service';
import { GetPaymentReceivedInvoices } from './queries/GetPaymentReceivedInvoices.service'; import { GetPaymentReceivedInvoices } from './queries/GetPaymentReceivedInvoices.service';
// import { PaymentReceiveNotifyBySms } from './PaymentReceivedSmsNotify';
import { GetPaymentReceivedPdfService } from './queries/GetPaymentReceivedPdf.service'; import { GetPaymentReceivedPdfService } from './queries/GetPaymentReceivedPdf.service';
// import { SendPaymentReceiveMailNotification } from './PaymentReceivedMailNotification';
import { GetPaymentReceivedStateService } from './queries/GetPaymentReceivedState.service'; import { GetPaymentReceivedStateService } from './queries/GetPaymentReceivedState.service';
import { GetPaymentsReceivedService } from './queries/GetPaymentsReceived.service'; import { GetPaymentsReceivedService } from './queries/GetPaymentsReceived.service';
import { SendPaymentReceiveMailNotification } from './commands/PaymentReceivedMailNotification';
@Injectable() @Injectable()
export class PaymentReceivesApplication { export class PaymentReceivesApplication {
@@ -29,8 +24,7 @@ export class PaymentReceivesApplication {
private getPaymentsReceivedService: GetPaymentsReceivedService, private getPaymentsReceivedService: GetPaymentsReceivedService,
private getPaymentReceivedService: GetPaymentReceivedService, private getPaymentReceivedService: GetPaymentReceivedService,
private getPaymentReceiveInvoicesService: GetPaymentReceivedInvoices, private getPaymentReceiveInvoicesService: GetPaymentReceivedInvoices,
// private paymentSmsNotify: PaymentReceiveNotifyBySms, private sendPaymentReceiveMailNotification: SendPaymentReceiveMailNotification,
// private paymentMailNotify: SendPaymentReceiveMailNotification,
private getPaymentReceivePdfService: GetPaymentReceivedPdfService, private getPaymentReceivePdfService: GetPaymentReceivedPdfService,
private getPaymentReceivedStateService: GetPaymentReceivedStateService, 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<IPaymentReceivedSmsDetails> => {
// return this.paymentSmsNotify.smsDetails(tenantId, paymentReceiveId);
// };
/** /**
* Notify customer via mail about payment receive details. * Notify customer via mail about payment receive details.
* @param {number} tenantId
* @param {number} paymentReceiveId * @param {number} paymentReceiveId
* @param {IPaymentReceiveMailOpts} messageOpts * @param {PaymentReceiveMailOptsDTO} messageOpts
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
// public notifyPaymentByMail( public notifyPaymentByMail(
// tenantId: number, paymentReceiveId: number,
// paymentReceiveId: number, messageOpts: PaymentReceiveMailOptsDTO,
// messageOpts: PaymentReceiveMailOptsDTO, ): Promise<void> {
// ): Promise<void> { return this.sendPaymentReceiveMailNotification.triggerMail(
// return this.paymentMailNotify.triggerMail( paymentReceiveId,
// tenantId, messageOpts,
// paymentReceiveId, );
// messageOpts, }
// );
// }
/** /**
* Retrieves the default mail options of the given payment transaction. * Retrieves the default mail options of the given payment transaction.
* @param {number} tenantId * @param {number} paymentReceiveId - Payment receive id.
* @param {number} paymentReceiveId
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
// public getPaymentMailOptions(tenantId: number, paymentReceiveId: number) { public getPaymentMailOptions(paymentReceiveId: number) {
// return this.paymentMailNotify.getMailOptions(tenantId, paymentReceiveId); return this.sendPaymentReceiveMailNotification.getMailOptions(
// } paymentReceiveId,
);
}
/** /**
* Retrieve pdf content of the given payment receive. * Retrieve pdf content of the given payment receive.

View File

@@ -3,6 +3,7 @@ import {
Controller, Controller,
Delete, Delete,
Get, Get,
HttpCode,
Param, Param,
ParseIntPipe, ParseIntPipe,
Post, Post,
@@ -14,9 +15,10 @@ import {
IPaymentReceivedCreateDTO, IPaymentReceivedCreateDTO,
IPaymentReceivedEditDTO, IPaymentReceivedEditDTO,
IPaymentsReceivedFilter, IPaymentsReceivedFilter,
PaymentReceiveMailOptsDTO,
} from './types/PaymentReceived.types'; } from './types/PaymentReceived.types';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
@Controller('payments-received') @Controller('payments-received')
@ApiTags('payments-received') @ApiTags('payments-received')
@@ -24,7 +26,38 @@ import { ApiTags } from '@nestjs/swagger';
export class PaymentReceivesController { export class PaymentReceivesController {
constructor(private paymentReceivesApplication: PaymentReceivesApplication) {} 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() @Post()
@ApiOperation({ summary: 'Create a new payment received.' })
public createPaymentReceived( public createPaymentReceived(
@Body() paymentReceiveDTO: IPaymentReceivedCreateDTO, @Body() paymentReceiveDTO: IPaymentReceivedCreateDTO,
) { ) {
@@ -34,6 +67,7 @@ export class PaymentReceivesController {
} }
@Put(':id') @Put(':id')
@ApiOperation({ summary: 'Edit the given payment received.' })
public editPaymentReceive( public editPaymentReceive(
@Param('id', ParseIntPipe) paymentReceiveId: number, @Param('id', ParseIntPipe) paymentReceiveId: number,
@Body() paymentReceiveDTO: IPaymentReceivedEditDTO, @Body() paymentReceiveDTO: IPaymentReceivedEditDTO,
@@ -45,6 +79,7 @@ export class PaymentReceivesController {
} }
@Delete(':id') @Delete(':id')
@ApiOperation({ summary: 'Delete the given payment received.' })
public deletePaymentReceive( public deletePaymentReceive(
@Param('id', ParseIntPipe) paymentReceiveId: number, @Param('id', ParseIntPipe) paymentReceiveId: number,
) { ) {
@@ -54,16 +89,27 @@ export class PaymentReceivesController {
} }
@Get() @Get()
@ApiOperation({ summary: 'Retrieves the payment received list.' })
public getPaymentsReceived(@Query() filterDTO: IPaymentsReceivedFilter) { public getPaymentsReceived(@Query() filterDTO: IPaymentsReceivedFilter) {
return this.paymentReceivesApplication.getPaymentsReceived(filterDTO); return this.paymentReceivesApplication.getPaymentsReceived(filterDTO);
} }
@Get('state') @Get('state')
@ApiOperation({ summary: 'Retrieves the payment received state.' })
@ApiResponse({
status: 200,
description: 'The payment received state has been successfully retrieved.',
})
public getPaymentReceivedState() { public getPaymentReceivedState() {
return this.paymentReceivesApplication.getPaymentReceivedState(); return this.paymentReceivesApplication.getPaymentReceivedState();
} }
@Get(':id/invoices') @Get(':id/invoices')
@ApiOperation({ summary: 'Retrieves the payment received invoices.' })
@ApiResponse({
status: 200,
description: 'The payment received invoices have been successfully retrieved.',
})
public getPaymentReceiveInvoices( public getPaymentReceiveInvoices(
@Param('id', ParseIntPipe) paymentReceiveId: number, @Param('id', ParseIntPipe) paymentReceiveId: number,
) { ) {
@@ -73,6 +119,11 @@ export class PaymentReceivesController {
} }
@Get(':id') @Get(':id')
@ApiOperation({ summary: 'Retrieves the payment received details.' })
@ApiResponse({
status: 200,
description: 'The payment received details have been successfully retrieved.',
})
public getPaymentReceive( public getPaymentReceive(
@Param('id', ParseIntPipe) paymentReceiveId: number, @Param('id', ParseIntPipe) paymentReceiveId: number,
) { ) {
@@ -80,6 +131,11 @@ export class PaymentReceivesController {
} }
@Get(':id/pdf') @Get(':id/pdf')
@ApiOperation({ summary: 'Retrieves the payment received pdf.' })
@ApiResponse({
status: 200,
description: 'The payment received pdf has been successfully retrieved.',
})
public getPaymentReceivePdf( public getPaymentReceivePdf(
@Param('id', ParseIntPipe) paymentReceivedId: number, @Param('id', ParseIntPipe) paymentReceivedId: number,
) { ) {

View File

@@ -1,9 +1,10 @@
import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { import {
Body, Body,
Controller, Controller,
Delete, Delete,
Get, Get,
HttpCode,
Param, Param,
ParseIntPipe, ParseIntPipe,
Post, Post,
@@ -32,6 +33,10 @@ export class SaleEstimatesController {
@Post() @Post()
@ApiOperation({ summary: 'Create a new sale estimate.' }) @ApiOperation({ summary: 'Create a new sale estimate.' })
@ApiResponse({
status: 200,
description: 'Sale estimate created successfully',
})
public createSaleEstimate( public createSaleEstimate(
@Body() estimateDTO: ISaleEstimateDTO, @Body() estimateDTO: ISaleEstimateDTO,
): Promise<SaleEstimate> { ): Promise<SaleEstimate> {
@@ -40,6 +45,14 @@ export class SaleEstimatesController {
@Put(':id') @Put(':id')
@ApiOperation({ summary: 'Edit the given sale estimate.' }) @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( public editSaleEstimate(
@Param('id', ParseIntPipe) estimateId: number, @Param('id', ParseIntPipe) estimateId: number,
@Body() estimateDTO: ISaleEstimateDTO, @Body() estimateDTO: ISaleEstimateDTO,
@@ -52,6 +65,14 @@ export class SaleEstimatesController {
@Delete(':id') @Delete(':id')
@ApiOperation({ summary: 'Delete the given sale estimate.' }) @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( public deleteSaleEstimate(
@Param('id', ParseIntPipe) estimateId: number, @Param('id', ParseIntPipe) estimateId: number,
): Promise<void> { ): Promise<void> {
@@ -60,18 +81,30 @@ export class SaleEstimatesController {
@Get('state') @Get('state')
@ApiOperation({ summary: 'Retrieves the sale estimate state.' }) @ApiOperation({ summary: 'Retrieves the sale estimate state.' })
@ApiResponse({
status: 200,
description: 'Sale estimate state retrieved successfully',
})
public getSaleEstimateState() { public getSaleEstimateState() {
return this.saleEstimatesApplication.getSaleEstimateState(); return this.saleEstimatesApplication.getSaleEstimateState();
} }
@Get() @Get()
@ApiOperation({ summary: 'Retrieves the sale estimates.' }) @ApiOperation({ summary: 'Retrieves the sale estimates.' })
@ApiResponse({
status: 200,
description: 'Sale estimates retrieved successfully',
})
public getSaleEstimates(@Query() filterDTO: ISalesEstimatesFilter) { public getSaleEstimates(@Query() filterDTO: ISalesEstimatesFilter) {
return this.saleEstimatesApplication.getSaleEstimates(filterDTO); return this.saleEstimatesApplication.getSaleEstimates(filterDTO);
} }
@Post(':id/deliver') @Post(':id/deliver')
@ApiOperation({ summary: 'Deliver the given sale estimate.' }) @ApiOperation({ summary: 'Deliver the given sale estimate.' })
@ApiResponse({
status: 200,
description: 'Sale estimate delivered successfully',
})
public deliverSaleEstimate( public deliverSaleEstimate(
@Param('id', ParseIntPipe) saleEstimateId: number, @Param('id', ParseIntPipe) saleEstimateId: number,
): Promise<void> { ): Promise<void> {
@@ -121,6 +154,7 @@ export class SaleEstimatesController {
} }
@Post(':id/mail') @Post(':id/mail')
@HttpCode(200)
@ApiOperation({ summary: 'Send the given sale estimate by mail.' }) @ApiOperation({ summary: 'Send the given sale estimate by mail.' })
public sendSaleEstimateMail( public sendSaleEstimateMail(
@Param('id', ParseIntPipe) saleEstimateId: number, @Param('id', ParseIntPipe) saleEstimateId: number,

View File

@@ -14,11 +14,13 @@ import {
ISaleInvoiceCreateDTO, ISaleInvoiceCreateDTO,
ISaleInvoiceEditDTO, ISaleInvoiceEditDTO,
ISaleInvoiceWriteoffDTO, ISaleInvoiceWriteoffDTO,
InvoiceNotificationType, ISalesInvoicesFilter,
SaleInvoiceMailState,
SendInvoiceMailDTO,
} from './SaleInvoice.types'; } from './SaleInvoice.types';
import { SaleInvoiceApplication } from './SaleInvoices.application'; import { SaleInvoiceApplication } from './SaleInvoices.application';
import { PublicRoute } from '../Auth/Jwt.guard'; import { PublicRoute } from '../Auth/Jwt.guard';
import { ApiOperation, ApiTags } from '@nestjs/swagger'; import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
@Controller('sale-invoices') @Controller('sale-invoices')
@ApiTags('sale-invoices') @ApiTags('sale-invoices')
@@ -28,12 +30,33 @@ export class SaleInvoicesController {
@Post() @Post()
@ApiOperation({ summary: 'Create a new sale invoice.' }) @ApiOperation({ summary: 'Create a new sale invoice.' })
@ApiResponse({
status: 201,
description: 'Sale invoice created successfully',
})
createSaleInvoice(@Body() saleInvoiceDTO: ISaleInvoiceCreateDTO) { createSaleInvoice(@Body() saleInvoiceDTO: ISaleInvoiceCreateDTO) {
return this.saleInvoiceApplication.createSaleInvoice(saleInvoiceDTO); 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') @Put(':id')
@ApiOperation({ summary: 'Edit the given sale invoice.' }) @ApiOperation({ summary: 'Edit the given sale invoice.' })
@ApiResponse({
status: 200,
description: 'Sale invoice edited successfully',
})
editSaleInvoice( editSaleInvoice(
@Param('id', ParseIntPipe) id: number, @Param('id', ParseIntPipe) id: number,
@Body() saleInvoiceDTO: ISaleInvoiceEditDTO, @Body() saleInvoiceDTO: ISaleInvoiceEditDTO,
@@ -47,10 +70,11 @@ export class SaleInvoicesController {
return this.saleInvoiceApplication.deleteSaleInvoice(id); return this.saleInvoiceApplication.deleteSaleInvoice(id);
} }
// @Get() @Get()
// getSaleInvoices(@Query() filterDTO: ISalesInvoicesFilter) { @ApiOperation({ summary: 'Retrieves the sale invoices.' })
// return this.saleInvoiceApplication.getSaleInvoices(filterDTO); getSaleInvoices(@Query() filterDTO: ISalesInvoicesFilter) {
// } return this.saleInvoiceApplication.getSaleInvoices(filterDTO);
}
@Get(':id') @Get(':id')
@ApiOperation({ summary: 'Retrieves the sale invoice details.' }) @ApiOperation({ summary: 'Retrieves the sale invoice details.' })
@@ -111,58 +135,15 @@ export class SaleInvoicesController {
return this.saleInvoiceApplication.saleInvoiceHtml(id); return this.saleInvoiceApplication.saleInvoiceHtml(id);
} }
@Post(':id/notify-sms') @Get(':id/mail-state')
@ApiOperation({ summary: 'Notify the sale invoice by SMS.' }) @ApiOperation({ summary: 'Retrieves the sale invoice mail state.' })
notifySaleInvoiceBySms( @ApiResponse({
status: 200,
description: 'Sale invoice mail state retrieved successfully',
})
getSaleInvoiceMailState(
@Param('id', ParseIntPipe) id: number, @Param('id', ParseIntPipe) id: number,
@Body('type') notificationType: InvoiceNotificationType, ): Promise<SaleInvoiceMailState> {
) { return this.saleInvoiceApplication.getSaleInvoiceMailState(id);
// return this.saleInvoiceApplication.notifySaleInvoiceBySms(
// id,
// notificationType,
// );
} }
// @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<SaleInvoiceMailState> {
// // return this.saleInvoiceApplication.getSaleInvoiceMailState(id);
// }
} }

View File

@@ -3,6 +3,7 @@ import {
Controller, Controller,
Delete, Delete,
Get, Get,
HttpCode,
Param, Param,
ParseIntPipe, ParseIntPipe,
Post, Post,
@@ -25,6 +26,20 @@ export class SaleReceiptsController {
return this.saleReceiptApplication.createSaleReceipt(saleReceiptDTO); 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') @Put(':id')
@ApiOperation({ summary: 'Edit the given sale receipt.' }) @ApiOperation({ summary: 'Edit the given sale receipt.' })
editSaleReceipt( editSaleReceipt(

View File

@@ -4,7 +4,7 @@ import {
} from '../constants'; } from '../constants';
import { mergeAndValidateMailOptions } from '@/modules/MailNotification/utils'; import { mergeAndValidateMailOptions } from '@/modules/MailNotification/utils';
import { transformReceiptToMailDataArgs } from '../utils'; import { transformReceiptToMailDataArgs } from '../utils';
import { Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import { GetSaleReceipt } from '../queries/GetSaleReceipt.service'; import { GetSaleReceipt } from '../queries/GetSaleReceipt.service';
import { SaleReceiptsPdfService } from '../queries/SaleReceiptsPdf.service'; import { SaleReceiptsPdfService } from '../queries/SaleReceiptsPdf.service';
import { ContactMailNotification } from '@/modules/MailNotification/ContactMailNotification'; import { ContactMailNotification } from '@/modules/MailNotification/ContactMailNotification';
@@ -34,6 +34,9 @@ export class SaleReceiptMailNotification {
private readonly contactMailNotification: ContactMailNotification, private readonly contactMailNotification: ContactMailNotification,
private readonly eventEmitter: EventEmitter2, private readonly eventEmitter: EventEmitter2,
private readonly mailTransporter: MailTransporter, private readonly mailTransporter: MailTransporter,
@Inject(SaleReceipt.name)
private readonly saleReceiptModel: typeof SaleReceipt
) {} ) {}
/** /**
@@ -67,7 +70,7 @@ export class SaleReceiptMailNotification {
public async getMailOptions( public async getMailOptions(
saleReceiptId: number, saleReceiptId: number,
): Promise<SaleReceiptMailOpts> { ): Promise<SaleReceiptMailOpts> {
const saleReceipt = await SaleReceipt.query() const saleReceipt = await this.saleReceiptModel.query()
.findById(saleReceiptId) .findById(saleReceiptId)
.throwIfNotFound(); .throwIfNotFound();

View File

@@ -129,4 +129,37 @@ describe('Payment Received (e2e)', () => {
.set('organization-id', orgainzationId) .set('organization-id', orgainzationId)
.expect(200); .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);
});
}); });

View File

@@ -119,4 +119,41 @@ describe('Sale Estimates (e2e)', () => {
.set('organization-id', orgainzationId) .set('organization-id', orgainzationId)
.expect(200); .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);
});
}); });

View File

@@ -84,6 +84,18 @@ describe('Sale Invoices (e2e)', () => {
.expect(200); .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 () => { it('/sale-invoices/:id (GET)', async () => {
const response = await request(app.getHttpServer()) const response = await request(app.getHttpServer())
.post('/sale-invoices') .post('/sale-invoices')
@@ -172,4 +184,34 @@ describe('Sale Invoices (e2e)', () => {
.set('organization-id', orgainzationId) .set('organization-id', orgainzationId)
.expect(200); .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);
});
}); });

View File

@@ -90,6 +90,13 @@ describe('Sale Receipts (e2e)', () => {
.expect(200); .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 () => { it('/sale-receipts/:id (GET)', async () => {
const response = await request(app.getHttpServer()) const response = await request(app.getHttpServer())
.post('/sale-receipts') .post('/sale-receipts')
@@ -103,4 +110,16 @@ describe('Sale Receipts (e2e)', () => {
.set('organization-id', orgainzationId) .set('organization-id', orgainzationId)
.expect(200); .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);
});
}); });