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 { SaleEstimatePdfTemplate } from '../Invoices/SaleEstimatePdfTemplate';
import { transformEstimateToPdfTemplate } from './utils';
import { EstimatePdfBrandingAttributes } from './constants';
import events from '@/subscribers/events';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
@Service()
export class SaleEstimatesPdf {
@@ -24,6 +26,9 @@ export class SaleEstimatesPdf {
@Inject()
private estimatePdfTemplate: SaleEstimatePdfTemplate;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieve sale invoice pdf content.
* @param {number} tenantId -
@@ -50,6 +55,13 @@ export class SaleEstimatesPdf {
tenantId,
htmlContent
);
const eventPayload = { tenantId, saleEstimateId };
// Triggers the `onSaleEstimatePdfViewed` event.
await this.eventPublisher.emitAsync(
events.saleEstimate.onPdfViewed,
eventPayload
);
return [content, filename];
}