mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feat: payment received mail preview
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import {
|
||||
ReceiptEmailTemplateProps,
|
||||
renderReceiptEmailTemplate,
|
||||
} from '@bigcapital/email-components';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { GetSaleReceipt } from './GetSaleReceipt';
|
||||
import { GetPdfTemplate } from '@/services/PdfTemplate/GetPdfTemplate';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
import { GetSaleReceiptMailTemplateAttributesTransformer } from './GetSaleReceiptMailTemplateAttributesTransformer';
|
||||
|
||||
@Service()
|
||||
export class GetSaleReceiptMailTemplate {
|
||||
@Inject()
|
||||
private getReceiptService: GetSaleReceipt;
|
||||
|
||||
@Inject()
|
||||
private transformer: TransformerInjectable;
|
||||
|
||||
@Inject()
|
||||
private getBrandingTemplate: GetPdfTemplate;
|
||||
|
||||
/**
|
||||
* Retrieves the mail template attributes of the given estimate.
|
||||
* Estimate template attributes are composed of the estimate and branding template attributes.
|
||||
* @param {number} tenantId
|
||||
* @param {number} receiptId - Receipt id.
|
||||
* @returns {Promise<EstimatePaymentEmailProps>}
|
||||
*/
|
||||
public async getMailTemplateAttributes(
|
||||
tenantId: number,
|
||||
receiptId: number
|
||||
): Promise<ReceiptEmailTemplateProps> {
|
||||
const receipt = await this.getReceiptService.getSaleReceipt(
|
||||
tenantId,
|
||||
receiptId
|
||||
);
|
||||
const brandingTemplate = await this.getBrandingTemplate.getPdfTemplate(
|
||||
tenantId,
|
||||
receipt.pdfTemplateId
|
||||
);
|
||||
const mailTemplateAttributes = await this.transformer.transform(
|
||||
tenantId,
|
||||
receipt,
|
||||
new GetSaleReceiptMailTemplateAttributesTransformer(),
|
||||
{
|
||||
receipt,
|
||||
brandingTemplate,
|
||||
}
|
||||
);
|
||||
return mailTemplateAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the mail template html content.
|
||||
* @param {number} tenantId
|
||||
* @param {number} estimateId
|
||||
* @param overrideAttributes
|
||||
* @returns
|
||||
*/
|
||||
public async getMailTemplate(
|
||||
tenantId: number,
|
||||
estimateId: number,
|
||||
overrideAttributes?: Partial<any>
|
||||
): Promise<string> {
|
||||
const attributes = await this.getMailTemplateAttributes(
|
||||
tenantId,
|
||||
estimateId
|
||||
);
|
||||
const mergedAttributes = {
|
||||
...attributes,
|
||||
...overrideAttributes,
|
||||
};
|
||||
return renderReceiptEmailTemplate(mergedAttributes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||
|
||||
export class GetSaleReceiptMailTemplateAttributesTransformer extends Transformer {}
|
||||
@@ -17,6 +17,7 @@ import { mergeAndValidateMailOptions } from '@/services/MailNotification/utils';
|
||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||
import events from '@/subscribers/events';
|
||||
import { transformReceiptToMailDataArgs } from './utils';
|
||||
import { GetSaleReceiptMailTemplate } from './GetSaleReceiptMailTemplate';
|
||||
|
||||
@Service()
|
||||
export class SaleReceiptMailNotification {
|
||||
@@ -32,6 +33,9 @@ export class SaleReceiptMailNotification {
|
||||
@Inject()
|
||||
private contactMailNotification: ContactMailNotification;
|
||||
|
||||
@Inject()
|
||||
private getReceiptMailTemplate: GetSaleReceiptMailTemplate;
|
||||
|
||||
@Inject()
|
||||
private eventPublisher: EventPublisher;
|
||||
|
||||
@@ -133,7 +137,15 @@ export class SaleReceiptMailNotification {
|
||||
mailOptions,
|
||||
formatterArgs
|
||||
)) as SaleReceiptMailOpts;
|
||||
return formattedOptions;
|
||||
|
||||
const message = await this.getReceiptMailTemplate.getMailTemplate(
|
||||
tenantId,
|
||||
receiptId,
|
||||
{
|
||||
message: formattedOptions.message,
|
||||
}
|
||||
);
|
||||
return { ...formattedOptions, message };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user