Files
bigcapital/packages/server-nest/src/modules/SaleInvoices/processors/SendSaleInvoiceMail.processor.ts
Ahmed Bouhuolia 9eee0b384d refactor: nestjs
2025-02-07 20:28:35 +02:00

31 lines
947 B
TypeScript

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