fix: sending mail jobs

This commit is contained in:
Ahmed Bouhuolia
2025-12-05 00:07:26 +02:00
parent 32d74b0413
commit c3dc26a1e4
11 changed files with 100 additions and 31 deletions

View File

@@ -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;
}
}
}