mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import { Inject, Service } from 'typedi';
|
|
import { GetPdfTemplate } from '@/services/PdfTemplate/GetPdfTemplate';
|
|
import { GetSaleInvoice } from './GetSaleInvoice';
|
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
|
import {
|
|
InvoicePaymentEmailProps,
|
|
renderInvoicePaymentEmail,
|
|
} from '@bigcapital/email-components';
|
|
import { GetInvoiceMailTemplateAttributesTransformer } from './GetInvoicePaymentMailAttributesTransformer';
|
|
|
|
@Service()
|
|
export class GetInvoicePaymentMail {
|
|
@Inject()
|
|
private getSaleInvoiceService: GetSaleInvoice;
|
|
|
|
@Inject()
|
|
private getBrandingTemplate: GetPdfTemplate;
|
|
|
|
@Inject()
|
|
private transformer: TransformerInjectable;
|
|
|
|
/**
|
|
* Retrieves the mail template attributes of the given invoice.
|
|
* @param {number} tenantId - Tenant id.
|
|
* @param {number} invoiceId - Invoice id.
|
|
*/
|
|
public async getMailTemplateAttributes(tenantId: number, invoiceId: number) {
|
|
const invoice = await this.getSaleInvoiceService.getSaleInvoice(
|
|
tenantId,
|
|
invoiceId
|
|
);
|
|
const brandingTemplate = await this.getBrandingTemplate.getPdfTemplate(
|
|
tenantId,
|
|
invoice.pdfTemplateId
|
|
);
|
|
const mailTemplateAttributes = await this.transformer.transform(
|
|
tenantId,
|
|
invoice,
|
|
new GetInvoiceMailTemplateAttributesTransformer(),
|
|
{
|
|
invoice,
|
|
brandingTemplate,
|
|
}
|
|
);
|
|
return mailTemplateAttributes;
|
|
}
|
|
|
|
/**
|
|
* Retrieves the mail template html content.
|
|
* @param {number} tenantId - Tenant id.
|
|
* @param {number} invoiceId - Invoice id.
|
|
*/
|
|
public async getMailTemplate(
|
|
tenantId: number,
|
|
invoiceId: number,
|
|
overrideAttributes?: Partial<InvoicePaymentEmailProps>
|
|
): Promise<string> {
|
|
const attributes = await this.getMailTemplateAttributes(
|
|
tenantId,
|
|
invoiceId
|
|
);
|
|
const mergedAttributes = { ...attributes, ...overrideAttributes };
|
|
|
|
return renderInvoicePaymentEmail(mergedAttributes);
|
|
}
|
|
}
|