mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
fix: sending mail jobs
This commit is contained in:
@@ -1,19 +1,39 @@
|
||||
import { Process, Processor } from '@nestjs/bull';
|
||||
import { Job } from 'bull';
|
||||
import { Inject, Scope } from '@nestjs/common';
|
||||
import { JOB_REF } from '@nestjs/bull';
|
||||
import {
|
||||
SendSaleEstimateMailJob,
|
||||
SendSaleEstimateMailQueue,
|
||||
} from '../types/SaleEstimates.types';
|
||||
import { SendSaleEstimateMail } from '../commands/SendSaleEstimateMail';
|
||||
import { ClsService, UseCls } from 'nestjs-cls';
|
||||
|
||||
@Processor(SendSaleEstimateMailQueue)
|
||||
@Processor({
|
||||
name: SendSaleEstimateMailQueue,
|
||||
scope: Scope.REQUEST,
|
||||
})
|
||||
export class SendSaleEstimateMailProcess {
|
||||
constructor(private readonly sendEstimateMailService: SendSaleEstimateMail) {}
|
||||
constructor(
|
||||
private readonly sendEstimateMailService: SendSaleEstimateMail,
|
||||
private readonly clsService: ClsService,
|
||||
@Inject(JOB_REF)
|
||||
private readonly jobRef: Job,
|
||||
) { }
|
||||
|
||||
@Process(SendSaleEstimateMailJob)
|
||||
async handleSendMail(job: Job) {
|
||||
const { saleEstimateId, messageOptions } = job.data;
|
||||
@UseCls()
|
||||
async handleSendMail() {
|
||||
const { saleEstimateId, messageOptions, organizationId, userId } = this.jobRef.data;
|
||||
|
||||
await this.sendEstimateMailService.sendMail(saleEstimateId, messageOptions);
|
||||
this.clsService.set('organizationId', organizationId);
|
||||
this.clsService.set('userId', userId);
|
||||
|
||||
try {
|
||||
await this.sendEstimateMailService.sendMail(saleEstimateId, messageOptions);
|
||||
} catch (error) {
|
||||
console.error('Failed to process estimate mail job:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user