mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
feat: track more services events
This commit is contained in:
@@ -9,6 +9,7 @@ export const SALE_ESTIMATE_CREATED = 'Sale estimate created';
|
|||||||
export const SALE_ESTIMATE_EDITED = 'Sale estimate edited';
|
export const SALE_ESTIMATE_EDITED = 'Sale estimate edited';
|
||||||
export const SALE_ESTIMATE_DELETED = 'Sale estimate deleted';
|
export const SALE_ESTIMATE_DELETED = 'Sale estimate deleted';
|
||||||
export const SALE_ESTIMATE_PDF_VIEWED = 'Sale estimate PDF viewed';
|
export const SALE_ESTIMATE_PDF_VIEWED = 'Sale estimate PDF viewed';
|
||||||
|
export const SALE_ESTIMATE_VIEWED = 'Sale estimate viewed';
|
||||||
|
|
||||||
export const PAYMENT_RECEIVED_CREATED = 'Payment received created';
|
export const PAYMENT_RECEIVED_CREATED = 'Payment received created';
|
||||||
export const PAYMENT_RECEIVED_EDITED = 'payment received edited';
|
export const PAYMENT_RECEIVED_EDITED = 'payment received edited';
|
||||||
@@ -47,6 +48,8 @@ export const AUTH_RESET_PASSWORD = 'Auth reset password';
|
|||||||
export const SUBSCRIPTION_CANCELLED = 'Subscription cancelled';
|
export const SUBSCRIPTION_CANCELLED = 'Subscription cancelled';
|
||||||
export const SUBSCRIPTION_RESUMED = 'Subscription resumed';
|
export const SUBSCRIPTION_RESUMED = 'Subscription resumed';
|
||||||
export const SUBSCRIPTION_PLAN_CHANGED = 'Subscription plan changed';
|
export const SUBSCRIPTION_PLAN_CHANGED = 'Subscription plan changed';
|
||||||
|
export const SUBSCRIPTION_PAYMENT_SUCCEED = 'Subscription payment succeed';
|
||||||
|
export const SUBSCRIPTION_PAYMENT_FAILED = 'Subscription payment failed';
|
||||||
|
|
||||||
export const CUSTOMER_CREATED = 'Customer created';
|
export const CUSTOMER_CREATED = 'Customer created';
|
||||||
export const CUSTOMER_EDITED = 'Customer edited';
|
export const CUSTOMER_EDITED = 'Customer edited';
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import I18nService from '@/services/I18n/I18nService';
|
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { AccountTransformer } from './AccountTransform';
|
import { AccountTransformer } from './AccountTransform';
|
||||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||||
@@ -11,9 +10,6 @@ export class GetAccount {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private tenancy: HasTenancyService;
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private i18nService: I18nService;
|
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
private transformer: TransformerInjectable;
|
private transformer: TransformerInjectable;
|
||||||
|
|
||||||
@@ -44,10 +40,8 @@ export class GetAccount {
|
|||||||
new AccountTransformer(),
|
new AccountTransformer(),
|
||||||
{ accountsGraph }
|
{ accountsGraph }
|
||||||
);
|
);
|
||||||
const eventPayload = {
|
const eventPayload = { tenantId, accountId };
|
||||||
tenantId,
|
|
||||||
accountId,
|
|
||||||
};
|
|
||||||
// Triggers `onAccountViewed` event.
|
// Triggers `onAccountViewed` event.
|
||||||
await this.eventPublisher.emitAsync(events.accounts.onViewed, eventPayload);
|
await this.eventPublisher.emitAsync(events.accounts.onViewed, eventPayload);
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ export default class NewCashflowTransactionService {
|
|||||||
* @param {number} tenantId -
|
* @param {number} tenantId -
|
||||||
* @param {ICashflowOwnerContributionDTO} ownerContributionDTO
|
* @param {ICashflowOwnerContributionDTO} ownerContributionDTO
|
||||||
* @param {number} userId - User id.
|
* @param {number} userId - User id.
|
||||||
|
* @returns {Promise<ICashflowTransaction>}
|
||||||
*/
|
*/
|
||||||
public newCashflowTransaction = async (
|
public newCashflowTransaction = async (
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import Knex from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { IRefundCreditNote } from '@/interfaces';
|
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class RefundSyncCreditNoteBalance {
|
export default class RefundSyncCreditNoteBalance {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
SALE_ESTIMATE_EDITED,
|
SALE_ESTIMATE_EDITED,
|
||||||
SALE_ESTIMATE_DELETED,
|
SALE_ESTIMATE_DELETED,
|
||||||
SALE_ESTIMATE_PDF_VIEWED,
|
SALE_ESTIMATE_PDF_VIEWED,
|
||||||
|
SALE_ESTIMATE_VIEWED,
|
||||||
} from '@/constants/event-tracker';
|
} from '@/constants/event-tracker';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@@ -39,6 +40,10 @@ export class SaleEstimateEventsTracker extends EventSubscriber {
|
|||||||
events.saleEstimate.onPdfViewed,
|
events.saleEstimate.onPdfViewed,
|
||||||
this.handleTrackPdfViewedEstimateEvent
|
this.handleTrackPdfViewedEstimateEvent
|
||||||
);
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.saleEstimate.onViewed,
|
||||||
|
this.handleTrackViewedEstimateEvent
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleTrackEstimateCreatedEvent = ({
|
private handleTrackEstimateCreatedEvent = ({
|
||||||
@@ -80,4 +85,12 @@ export class SaleEstimateEventsTracker extends EventSubscriber {
|
|||||||
properties: {},
|
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 { PosthogService } from '../PostHog';
|
||||||
import {
|
import {
|
||||||
SUBSCRIPTION_CANCELLED,
|
SUBSCRIPTION_CANCELLED,
|
||||||
|
SUBSCRIPTION_PAYMENT_FAILED,
|
||||||
|
SUBSCRIPTION_PAYMENT_SUCCEED,
|
||||||
SUBSCRIPTION_PLAN_CHANGED,
|
SUBSCRIPTION_PLAN_CHANGED,
|
||||||
SUBSCRIPTION_RESUMED,
|
SUBSCRIPTION_RESUMED,
|
||||||
} from '@/constants/event-tracker';
|
} from '@/constants/event-tracker';
|
||||||
@@ -27,6 +29,14 @@ export class TransactionsLockingEventsTracker extends EventSubscriber {
|
|||||||
events.subscription.onSubscriptionPlanChanged,
|
events.subscription.onSubscriptionPlanChanged,
|
||||||
this.handleSubscriptionPlanChangedEvent
|
this.handleSubscriptionPlanChangedEvent
|
||||||
);
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.subscription.onSubscriptionPaymentSucceed,
|
||||||
|
this.handleSubscriptionPaymentFailedEvent
|
||||||
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.subscription.onSubscriptionPaymentFailed,
|
||||||
|
this.handleSubscriptionPaymentSucceed
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleSubscriptionResumedEvent = ({ tenantId }) => {
|
private handleSubscriptionResumedEvent = ({ tenantId }) => {
|
||||||
@@ -52,4 +62,20 @@ export class TransactionsLockingEventsTracker extends EventSubscriber {
|
|||||||
properties: {},
|
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).
|
* Creates a new item (service/product).
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {IItemCreateDTO} itemDTO
|
* @param {IItemCreateDTO} itemDTO
|
||||||
* @returns {Promise<IItem>}
|
* @returns {Promise<IItem>}
|
||||||
*/
|
*/
|
||||||
public async createItem(
|
public async createItem(
|
||||||
@@ -52,8 +52,8 @@ export class ItemsApplication {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the given item.
|
* Retrieves the given item.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {number} itemId
|
* @param {number} itemId
|
||||||
* @returns {Promise<IItem>}
|
* @returns {Promise<IItem>}
|
||||||
*/
|
*/
|
||||||
public getItem(tenantId: number, itemId: number): Promise<IItem> {
|
public getItem(tenantId: number, itemId: number): Promise<IItem> {
|
||||||
@@ -62,9 +62,9 @@ export class ItemsApplication {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Edits the given item (service/product).
|
* Edits the given item (service/product).
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {number} itemId
|
* @param {number} itemId
|
||||||
* @param {IItemEditDTO} itemDTO
|
* @param {IItemEditDTO} itemDTO
|
||||||
* @returns {Promise<IItem>}
|
* @returns {Promise<IItem>}
|
||||||
*/
|
*/
|
||||||
public editItem(tenantId: number, itemId: number, itemDTO: IItemEditDTO) {
|
public editItem(tenantId: number, itemId: number, itemDTO: IItemEditDTO) {
|
||||||
@@ -73,8 +73,8 @@ export class ItemsApplication {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the given item (service/product).
|
* Deletes the given item (service/product).
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {number} itemId
|
* @param {number} itemId
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
public deleteItem(tenantId: number, itemId: number) {
|
public deleteItem(tenantId: number, itemId: number) {
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|||||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||||
import { SaleEstimateTransfromer } from './SaleEstimateTransformer';
|
import { SaleEstimateTransfromer } from './SaleEstimateTransformer';
|
||||||
import { SaleEstimateValidators } from './SaleEstimateValidators';
|
import { SaleEstimateValidators } from './SaleEstimateValidators';
|
||||||
|
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||||
|
import events from '@/subscribers/events';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class GetSaleEstimate {
|
export class GetSaleEstimate {
|
||||||
@@ -15,6 +17,9 @@ export class GetSaleEstimate {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private validators: SaleEstimateValidators;
|
private validators: SaleEstimateValidators;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private eventPublisher: EventPublisher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the estimate details with associated entries.
|
* Retrieve the estimate details with associated entries.
|
||||||
* @async
|
* @async
|
||||||
@@ -35,10 +40,18 @@ export class GetSaleEstimate {
|
|||||||
this.validators.validateEstimateExistance(estimate);
|
this.validators.validateEstimateExistance(estimate);
|
||||||
|
|
||||||
// Transformes sale estimate model to POJO.
|
// Transformes sale estimate model to POJO.
|
||||||
return this.transformer.transform(
|
const transformed = await this.transformer.transform(
|
||||||
tenantId,
|
tenantId,
|
||||||
estimate,
|
estimate,
|
||||||
new SaleEstimateTransfromer()
|
new SaleEstimateTransfromer()
|
||||||
);
|
);
|
||||||
|
const eventPayload = { tenantId, saleEstimateId: estimateId };
|
||||||
|
|
||||||
|
// Triggers `onSaleEstimateViewed` event.
|
||||||
|
await this.eventPublisher.emitAsync(
|
||||||
|
events.saleEstimate.onViewed,
|
||||||
|
eventPayload
|
||||||
|
);
|
||||||
|
return transformed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ export default {
|
|||||||
* Sales estimates service.
|
* Sales estimates service.
|
||||||
*/
|
*/
|
||||||
saleEstimate: {
|
saleEstimate: {
|
||||||
|
onViewed: 'onSaleEstimateViewed',
|
||||||
onPdfViewed: 'onSaleEstimatePdfViewed',
|
onPdfViewed: 'onSaleEstimatePdfViewed',
|
||||||
|
|
||||||
onCreating: 'onSaleEstimateCreating',
|
onCreating: 'onSaleEstimateCreating',
|
||||||
|
|||||||
Reference in New Issue
Block a user