mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat: track more services events
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import I18nService from '@/services/I18n/I18nService';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { AccountTransformer } from './AccountTransform';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
@@ -11,9 +10,6 @@ export class GetAccount {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private i18nService: I18nService;
|
||||
|
||||
@Inject()
|
||||
private transformer: TransformerInjectable;
|
||||
|
||||
@@ -44,10 +40,8 @@ export class GetAccount {
|
||||
new AccountTransformer(),
|
||||
{ accountsGraph }
|
||||
);
|
||||
const eventPayload = {
|
||||
tenantId,
|
||||
accountId,
|
||||
};
|
||||
const eventPayload = { tenantId, accountId };
|
||||
|
||||
// Triggers `onAccountViewed` event.
|
||||
await this.eventPublisher.emitAsync(events.accounts.onViewed, eventPayload);
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ export default class NewCashflowTransactionService {
|
||||
* @param {number} tenantId -
|
||||
* @param {ICashflowOwnerContributionDTO} ownerContributionDTO
|
||||
* @param {number} userId - User id.
|
||||
* @returns {Promise<ICashflowTransaction>}
|
||||
*/
|
||||
public newCashflowTransaction = async (
|
||||
tenantId: number,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import Knex from 'knex';
|
||||
import { IRefundCreditNote } from '@/interfaces';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { Knex } from 'knex';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
|
||||
@Service()
|
||||
export default class RefundSyncCreditNoteBalance {
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
SALE_ESTIMATE_EDITED,
|
||||
SALE_ESTIMATE_DELETED,
|
||||
SALE_ESTIMATE_PDF_VIEWED,
|
||||
SALE_ESTIMATE_VIEWED,
|
||||
} from '@/constants/event-tracker';
|
||||
|
||||
@Service()
|
||||
@@ -39,6 +40,10 @@ export class SaleEstimateEventsTracker extends EventSubscriber {
|
||||
events.saleEstimate.onPdfViewed,
|
||||
this.handleTrackPdfViewedEstimateEvent
|
||||
);
|
||||
bus.subscribe(
|
||||
events.saleEstimate.onViewed,
|
||||
this.handleTrackViewedEstimateEvent
|
||||
);
|
||||
}
|
||||
|
||||
private handleTrackEstimateCreatedEvent = ({
|
||||
@@ -80,4 +85,12 @@ export class SaleEstimateEventsTracker extends EventSubscriber {
|
||||
properties: {},
|
||||
});
|
||||
};
|
||||
|
||||
private handleTrackViewedEstimateEvent = ({ tenantId }) => {
|
||||
this.posthog.trackEvent({
|
||||
distinctId: `tenant-${tenantId}`,
|
||||
event: SALE_ESTIMATE_VIEWED,
|
||||
properties: {},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import { ITransactionsLockingPartialUnlocked } from '@/interfaces';
|
||||
import { PosthogService } from '../PostHog';
|
||||
import {
|
||||
SUBSCRIPTION_CANCELLED,
|
||||
SUBSCRIPTION_PAYMENT_FAILED,
|
||||
SUBSCRIPTION_PAYMENT_SUCCEED,
|
||||
SUBSCRIPTION_PLAN_CHANGED,
|
||||
SUBSCRIPTION_RESUMED,
|
||||
} from '@/constants/event-tracker';
|
||||
@@ -27,6 +29,14 @@ export class TransactionsLockingEventsTracker extends EventSubscriber {
|
||||
events.subscription.onSubscriptionPlanChanged,
|
||||
this.handleSubscriptionPlanChangedEvent
|
||||
);
|
||||
bus.subscribe(
|
||||
events.subscription.onSubscriptionPaymentSucceed,
|
||||
this.handleSubscriptionPaymentFailedEvent
|
||||
);
|
||||
bus.subscribe(
|
||||
events.subscription.onSubscriptionPaymentFailed,
|
||||
this.handleSubscriptionPaymentSucceed
|
||||
);
|
||||
}
|
||||
|
||||
private handleSubscriptionResumedEvent = ({ tenantId }) => {
|
||||
@@ -52,4 +62,20 @@ export class TransactionsLockingEventsTracker extends EventSubscriber {
|
||||
properties: {},
|
||||
});
|
||||
};
|
||||
|
||||
private handleSubscriptionPaymentFailedEvent = ({ tenantId }) => {
|
||||
this.posthog.trackEvent({
|
||||
distinctId: `tenant-${tenantId}`,
|
||||
event: SUBSCRIPTION_PAYMENT_FAILED,
|
||||
properties: {},
|
||||
});
|
||||
};
|
||||
|
||||
private handleSubscriptionPaymentSucceed = ({ tenantId }) => {
|
||||
this.posthog.trackEvent({
|
||||
distinctId: `tenant-${tenantId}`,
|
||||
event: SUBSCRIPTION_PAYMENT_SUCCEED,
|
||||
properties: {},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ export class ItemsApplication {
|
||||
|
||||
/**
|
||||
* Creates a new item (service/product).
|
||||
* @param {number} tenantId
|
||||
* @param {IItemCreateDTO} itemDTO
|
||||
* @param {number} tenantId
|
||||
* @param {IItemCreateDTO} itemDTO
|
||||
* @returns {Promise<IItem>}
|
||||
*/
|
||||
public async createItem(
|
||||
@@ -52,8 +52,8 @@ export class ItemsApplication {
|
||||
|
||||
/**
|
||||
* Retrieves the given item.
|
||||
* @param {number} tenantId
|
||||
* @param {number} itemId
|
||||
* @param {number} tenantId
|
||||
* @param {number} itemId
|
||||
* @returns {Promise<IItem>}
|
||||
*/
|
||||
public getItem(tenantId: number, itemId: number): Promise<IItem> {
|
||||
@@ -62,9 +62,9 @@ export class ItemsApplication {
|
||||
|
||||
/**
|
||||
* Edits the given item (service/product).
|
||||
* @param {number} tenantId
|
||||
* @param {number} itemId
|
||||
* @param {IItemEditDTO} itemDTO
|
||||
* @param {number} tenantId
|
||||
* @param {number} itemId
|
||||
* @param {IItemEditDTO} itemDTO
|
||||
* @returns {Promise<IItem>}
|
||||
*/
|
||||
public editItem(tenantId: number, itemId: number, itemDTO: IItemEditDTO) {
|
||||
@@ -73,8 +73,8 @@ export class ItemsApplication {
|
||||
|
||||
/**
|
||||
* Deletes the given item (service/product).
|
||||
* @param {number} tenantId
|
||||
* @param {number} itemId
|
||||
* @param {number} tenantId
|
||||
* @param {number} itemId
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public deleteItem(tenantId: number, itemId: number) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user