feat: Track events of pdf documents views

This commit is contained in:
Ahmed Bouhuolia
2024-10-19 13:38:28 +02:00
parent de50b89e5c
commit bb299aa595
10 changed files with 128 additions and 8 deletions

View File

@@ -6,6 +6,8 @@ import HasTenancyService from '@/services/Tenancy/TenancyService';
import { transformInvoiceToPdfTemplate } from './utils';
import { InvoicePdfTemplateAttributes } from '@/interfaces';
import { SaleInvoicePdfTemplate } from './SaleInvoicePdfTemplate';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
@Service()
export class SaleInvoicePdf {
@@ -24,6 +26,9 @@ export class SaleInvoicePdf {
@Inject()
private invoiceBrandingTemplateService: SaleInvoicePdfTemplate;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieve sale invoice pdf content.
* @param {number} tenantId - Tenant Id.
@@ -50,7 +55,13 @@ export class SaleInvoicePdf {
tenantId,
htmlContent
);
const eventPayload = { tenantId, saleInvoiceId: invoiceId };
// Triggers the `onSaleInvoicePdfViewed` event.
await this.eventPublisher.emitAsync(
events.saleInvoice.onPdfViewed,
eventPayload
);
return [buffer, filename];
}