refactor: nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-02-07 20:28:35 +02:00
parent 9539003cac
commit 9eee0b384d
26 changed files with 207 additions and 131 deletions

View File

@@ -0,0 +1,30 @@
import { JOB_REF, Process, Processor } from '@nestjs/bull';
import { Job } from 'bull';
import { SendSaleInvoiceMailJob, SendSaleInvoiceQueue } from '../constants';
import { SendSaleInvoiceMail } from '../commands/SendSaleInvoiceMail';
import { Inject, Scope } from '@nestjs/common';
import { REQUEST } from '@nestjs/core';
import { UseCls } from 'nestjs-cls';
@Processor({
name: SendSaleInvoiceQueue,
scope: Scope.REQUEST,
})
export class SendSaleInvoiceMailProcessor {
constructor(
private readonly sendSaleInvoiceMail: SendSaleInvoiceMail,
@Inject(REQUEST) private readonly request: Request,
@Inject(JOB_REF) private readonly jobRef: Job,
) {}
@Process(SendSaleInvoiceMailJob)
async handleSendInvoice() {
const { messageOptions, saleInvoiceId } = this.jobRef.data;
try {
await this.sendSaleInvoiceMail.sendMail(saleInvoiceId, messageOptions);
} catch (error) {
console.log(error);
}
}
}