feat: send invoice through mail

This commit is contained in:
Ahmed Bouhuolia
2023-12-18 21:28:53 +02:00
parent cfd4540a65
commit cd71900bdd
9 changed files with 218 additions and 20 deletions

View File

@@ -0,0 +1,33 @@
import Container, { Service } from 'typedi';
import events from '@/subscribers/events';
import { SendSaleInvoiceMail } from './SendSaleInvoiceMail';
@Service()
export class SendSaleInvoiceMailJob {
/**
* Constructor method.
*/
constructor(agenda) {
agenda.define(
'sale-invoice-mail-send',
{ priority: 'high', concurrency: 1 },
this.handler
);
}
/**
* Triggers sending invoice mail.
*/
private handler = async (job, done: Function) => {
const { tenantId, saleInvoiceId, messageDTO } = job.attrs.data;
const sendInvoiceMail = Container.get(SendSaleInvoiceMail);
try {
await sendInvoiceMail.triggerMail(tenantId, saleInvoiceId, messageDTO);
done();
} catch (error) {
console.log(error);
done(error);
}
};
}