feat: track more services events

This commit is contained in:
Ahmed Bouhuolia
2024-10-19 23:47:14 +02:00
parent ccbb399685
commit 32ba6f9a6c
9 changed files with 71 additions and 21 deletions

View File

@@ -3,6 +3,8 @@ import HasTenancyService from '@/services/Tenancy/TenancyService';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
import { SaleEstimateTransfromer } from './SaleEstimateTransformer';
import { SaleEstimateValidators } from './SaleEstimateValidators';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import events from '@/subscribers/events';
@Service()
export class GetSaleEstimate {
@@ -15,6 +17,9 @@ export class GetSaleEstimate {
@Inject()
private validators: SaleEstimateValidators;
@Inject()
private eventPublisher: EventPublisher;
/**
* Retrieve the estimate details with associated entries.
* @async
@@ -35,10 +40,18 @@ export class GetSaleEstimate {
this.validators.validateEstimateExistance(estimate);
// Transformes sale estimate model to POJO.
return this.transformer.transform(
const transformed = await this.transformer.transform(
tenantId,
estimate,
new SaleEstimateTransfromer()
);
const eventPayload = { tenantId, saleEstimateId: estimateId };
// Triggers `onSaleEstimateViewed` event.
await this.eventPublisher.emitAsync(
events.saleEstimate.onViewed,
eventPayload
);
return transformed;
}
}