mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
fix: sending mail jobs
This commit is contained in:
@@ -25,7 +25,10 @@ import {
|
||||
CreateSaleReceiptDto,
|
||||
EditSaleReceiptDto,
|
||||
} from './dtos/SaleReceipt.dto';
|
||||
import { ISalesReceiptsFilter } from './types/SaleReceipts.types';
|
||||
import {
|
||||
ISalesReceiptsFilter,
|
||||
SaleReceiptMailOptsDTO,
|
||||
} from './types/SaleReceipts.types';
|
||||
import { AcceptType } from '@/constants/accept-type';
|
||||
import { Response } from 'express';
|
||||
import { SaleReceiptResponseDto } from './dtos/SaleReceiptResponse.dto';
|
||||
@@ -87,7 +90,7 @@ export class SaleReceiptsController {
|
||||
return this.saleReceiptApplication.createSaleReceipt(saleReceiptDTO);
|
||||
}
|
||||
|
||||
@Put(':id/mail')
|
||||
@Post(':id/mail')
|
||||
@HttpCode(200)
|
||||
@ApiOperation({ summary: 'Send the sale receipt mail.' })
|
||||
@ApiParam({
|
||||
@@ -96,8 +99,11 @@ export class SaleReceiptsController {
|
||||
type: Number,
|
||||
description: 'The sale receipt id',
|
||||
})
|
||||
sendSaleReceiptMail(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.saleReceiptApplication.getSaleReceiptMail(id);
|
||||
sendSaleReceiptMail(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Body() messageOpts: SaleReceiptMailOptsDTO,
|
||||
) {
|
||||
return this.saleReceiptApplication.sendSaleReceiptMail(id, messageOpts);
|
||||
}
|
||||
|
||||
@Get('state')
|
||||
|
||||
@@ -1,24 +1,42 @@
|
||||
import { Process, Processor } from '@nestjs/bull';
|
||||
import { Job } from 'bull';
|
||||
import { SendSaleReceiptMailQueue } from '../constants';
|
||||
import { Inject, Scope } from '@nestjs/common';
|
||||
import { JOB_REF } from '@nestjs/bull';
|
||||
import { SendSaleReceiptMailQueue, SendSaleReceiptMailJob } from '../constants';
|
||||
import { SaleReceiptMailNotification } from '../commands/SaleReceiptMailNotification';
|
||||
import { SaleReceiptSendMailPayload } from '../types/SaleReceipts.types';
|
||||
import { ClsService } from 'nestjs-cls';
|
||||
import { ClsService, UseCls } from 'nestjs-cls';
|
||||
|
||||
@Processor(SendSaleReceiptMailQueue)
|
||||
@Processor({
|
||||
name: SendSaleReceiptMailQueue,
|
||||
scope: Scope.REQUEST,
|
||||
})
|
||||
export class SendSaleReceiptMailProcess {
|
||||
constructor(
|
||||
private readonly saleReceiptMailNotification: SaleReceiptMailNotification,
|
||||
private readonly clsService: ClsService,
|
||||
) {}
|
||||
|
||||
@Process(SendSaleReceiptMailQueue)
|
||||
async handleSendMailJob(job: Job<SaleReceiptSendMailPayload>) {
|
||||
const { messageOpts, saleReceiptId, organizationId, userId } = job.data;
|
||||
@Inject(JOB_REF)
|
||||
private readonly jobRef: Job<SaleReceiptSendMailPayload>,
|
||||
) { }
|
||||
|
||||
@Process(SendSaleReceiptMailJob)
|
||||
@UseCls()
|
||||
async handleSendMailJob() {
|
||||
const { messageOpts, saleReceiptId, organizationId, userId } =
|
||||
this.jobRef.data;
|
||||
|
||||
this.clsService.set('organizationId', organizationId);
|
||||
this.clsService.set('userId', userId);
|
||||
|
||||
await this.saleReceiptMailNotification.sendMail(saleReceiptId, messageOpts);
|
||||
try {
|
||||
await this.saleReceiptMailNotification.sendMail(
|
||||
saleReceiptId,
|
||||
messageOpts,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Failed to process receipt mail job:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user