mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
Merge pull request #650 from bigcapitalhq/cover-more-tracking-events
feat: Cover more tracking events.
This commit is contained in:
@@ -41,3 +41,21 @@ export const SALE_GROUP = 'Sale';
|
|||||||
export const PAYMENT_GROUP = 'Payment';
|
export const PAYMENT_GROUP = 'Payment';
|
||||||
export const BILL_GROUP = 'Bill';
|
export const BILL_GROUP = 'Bill';
|
||||||
export const EXPENSE_GROUP = 'Expense';
|
export const EXPENSE_GROUP = 'Expense';
|
||||||
|
|
||||||
|
export const MANUAL_JOURNAL_CREATED = 'Manual journal created';
|
||||||
|
export const MANUAL_JOURNAL_EDITED = 'Manual journal edited';
|
||||||
|
export const MANUAL_JOURNAL_DELETED = 'Manual journal deleted';
|
||||||
|
export const MANUAL_JOURNAL_PUBLISHED = 'Manual journal published';
|
||||||
|
|
||||||
|
export const CUSTOMER_CREATED = 'Customer created';
|
||||||
|
export const CUSTOMER_EDITED = 'Customer edited';
|
||||||
|
export const CUSTOMER_DELETED = 'Customer deleted';
|
||||||
|
|
||||||
|
export const VENDOR_CREATED = 'Vendor created';
|
||||||
|
export const VENDOR_EDITED = 'Vendor edited';
|
||||||
|
export const VENDOR_DELETED = 'Vendor deleted';
|
||||||
|
|
||||||
|
export const BANK_RULE_CREATED = 'Bank rule created';
|
||||||
|
export const BANK_RULE_EDITED = 'Bank rule edited';
|
||||||
|
export const BANK_RULE_DELETED = 'Bank rule deleted';
|
||||||
|
|
||||||
|
|||||||
@@ -241,6 +241,7 @@ export interface ICustomerEventCreatingPayload {
|
|||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
export interface ICustomerEventEditedPayload {
|
export interface ICustomerEventEditedPayload {
|
||||||
|
tenantId: number
|
||||||
customerId: number;
|
customerId: number;
|
||||||
customer: ICustomer;
|
customer: ICustomer;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export class EditCustomer {
|
|||||||
});
|
});
|
||||||
// Triggers `onCustomerEdited` event.
|
// Triggers `onCustomerEdited` event.
|
||||||
await this.eventPublisher.emitAsync(events.customers.onEdited, {
|
await this.eventPublisher.emitAsync(events.customers.onEdited, {
|
||||||
|
tenantId,
|
||||||
customerId,
|
customerId,
|
||||||
customer,
|
customer,
|
||||||
trx,
|
trx,
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
|
||||||
|
import {
|
||||||
|
IBankRuleEventCreatedPayload,
|
||||||
|
IBankRuleEventEditedPayload,
|
||||||
|
IBankRuleEventDeletedPayload,
|
||||||
|
} from '@/services/Banking/Rules/types'; // Updated import path for interfaces
|
||||||
|
import { PosthogService } from '../PostHog';
|
||||||
|
import events from '@/subscribers/events';
|
||||||
|
import {
|
||||||
|
BANK_RULE_CREATED,
|
||||||
|
BANK_RULE_EDITED,
|
||||||
|
BANK_RULE_DELETED,
|
||||||
|
} from '@/constants/event-tracker';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class BankRuleEventsTracker extends EventSubscriber {
|
||||||
|
@Inject()
|
||||||
|
private posthog: PosthogService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
*/
|
||||||
|
public attach(bus) {
|
||||||
|
bus.subscribe(
|
||||||
|
events.bankRules.onCreated,
|
||||||
|
this.handleTrackBankRuleCreatedEvent
|
||||||
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.bankRules.onEdited,
|
||||||
|
this.handleTrackEditedBankRuleEvent
|
||||||
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.bankRules.onDeleted,
|
||||||
|
this.handleTrackDeletedBankRuleEvent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleTrackBankRuleCreatedEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: IBankRuleEventCreatedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: BANK_RULE_CREATED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleTrackEditedBankRuleEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: IBankRuleEventEditedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: BANK_RULE_EDITED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleTrackDeletedBankRuleEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: IBankRuleEventDeletedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: BANK_RULE_DELETED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
|
||||||
|
import {
|
||||||
|
ICustomerEventCreatedPayload,
|
||||||
|
ICustomerEventEditedPayload,
|
||||||
|
ICustomerEventDeletedPayload,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import { PosthogService } from '../PostHog';
|
||||||
|
import events from '@/subscribers/events';
|
||||||
|
import {
|
||||||
|
CUSTOMER_CREATED,
|
||||||
|
CUSTOMER_EDITED,
|
||||||
|
CUSTOMER_DELETED,
|
||||||
|
} from '@/constants/event-tracker';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class CustomerEventsTracker extends EventSubscriber {
|
||||||
|
@Inject()
|
||||||
|
private posthog: PosthogService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
*/
|
||||||
|
public attach(bus) {
|
||||||
|
bus.subscribe(
|
||||||
|
events.customers.onCreated,
|
||||||
|
this.handleTrackCustomerCreatedEvent
|
||||||
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.customers.onEdited,
|
||||||
|
this.handleTrackEditedCustomerEvent
|
||||||
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.customers.onDeleted,
|
||||||
|
this.handleTrackDeletedCustomerEvent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleTrackCustomerCreatedEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: ICustomerEventCreatedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: CUSTOMER_CREATED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleTrackEditedCustomerEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: ICustomerEventEditedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: CUSTOMER_EDITED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleTrackDeletedCustomerEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: ICustomerEventDeletedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: CUSTOMER_DELETED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
|
||||||
|
import {
|
||||||
|
IManualJournalEventCreatedPayload,
|
||||||
|
IManualJournalEventEditedPayload,
|
||||||
|
IManualJournalEventDeletedPayload,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import { PosthogService } from '../PostHog';
|
||||||
|
import events from '@/subscribers/events';
|
||||||
|
import {
|
||||||
|
MANUAL_JOURNAL_CREATED,
|
||||||
|
MANUAL_JOURNAL_EDITED,
|
||||||
|
MANUAL_JOURNAL_DELETED,
|
||||||
|
} from '@/constants/event-tracker';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class ManualJournalEventsTracker extends EventSubscriber {
|
||||||
|
@Inject()
|
||||||
|
private posthog: PosthogService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
*/
|
||||||
|
public attach(bus) {
|
||||||
|
bus.subscribe(
|
||||||
|
events.manualJournals.onCreated,
|
||||||
|
this.handleTrackManualJournalCreatedEvent
|
||||||
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.manualJournals.onEdited,
|
||||||
|
this.handleTrackEditedManualJournalEvent
|
||||||
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.manualJournals.onDeleted,
|
||||||
|
this.handleTrackDeletedManualJournalEvent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleTrackManualJournalCreatedEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: IManualJournalEventCreatedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: MANUAL_JOURNAL_CREATED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleTrackEditedManualJournalEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: IManualJournalEventEditedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: MANUAL_JOURNAL_EDITED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleTrackDeletedManualJournalEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: IManualJournalEventDeletedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: MANUAL_JOURNAL_DELETED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { EventSubscriber } from '@/lib/EventPublisher/EventPublisher';
|
||||||
|
import {
|
||||||
|
IVendorEventCreatedPayload,
|
||||||
|
IVendorEventEditedPayload,
|
||||||
|
IVendorEventDeletedPayload,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import { PosthogService } from '../PostHog';
|
||||||
|
import events from '@/subscribers/events';
|
||||||
|
import {
|
||||||
|
VENDOR_CREATED,
|
||||||
|
VENDOR_EDITED,
|
||||||
|
VENDOR_DELETED,
|
||||||
|
} from '@/constants/event-tracker';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class VendorEventsTracker extends EventSubscriber {
|
||||||
|
@Inject()
|
||||||
|
private posthog: PosthogService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
*/
|
||||||
|
public attach(bus) {
|
||||||
|
bus.subscribe(events.vendors.onCreated, this.handleTrackVendorCreatedEvent);
|
||||||
|
bus.subscribe(events.vendors.onEdited, this.handleTrackEditedVendorEvent);
|
||||||
|
bus.subscribe(events.vendors.onDeleted, this.handleTrackDeletedVendorEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleTrackVendorCreatedEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: IVendorEventCreatedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: VENDOR_CREATED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleTrackEditedVendorEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: IVendorEventEditedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: VENDOR_EDITED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
private handleTrackDeletedVendorEvent = ({
|
||||||
|
tenantId,
|
||||||
|
}: IVendorEventDeletedPayload) => {
|
||||||
|
this.posthog.trackEvent({
|
||||||
|
distinctId: `tenant-${tenantId}`,
|
||||||
|
event: VENDOR_DELETED,
|
||||||
|
properties: {},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -7,6 +7,10 @@ import { ExpenseEventsTracker } from './ExpenseEventsTracker';
|
|||||||
import { AccountEventsTracker } from './AccountEventsTracker';
|
import { AccountEventsTracker } from './AccountEventsTracker';
|
||||||
import { AuthenticationEventsTracker } from './AuthenticationEventsTracker';
|
import { AuthenticationEventsTracker } from './AuthenticationEventsTracker';
|
||||||
import { ItemEventsTracker } from './ItemEventsTracker';
|
import { ItemEventsTracker } from './ItemEventsTracker';
|
||||||
|
import { CustomerEventsTracker } from './CustomerEventsTracker';
|
||||||
|
import { VendorEventsTracker } from './VendorEventsTracker';
|
||||||
|
import { ManualJournalEventsTracker } from './ManualJournalEventsTracker';
|
||||||
|
import { BankRuleEventsTracker } from './BankRuleEventsTracker';
|
||||||
|
|
||||||
export const EventsTrackerListeners = [
|
export const EventsTrackerListeners = [
|
||||||
SaleInvoiceEventsTracker,
|
SaleInvoiceEventsTracker,
|
||||||
@@ -17,5 +21,9 @@ export const EventsTrackerListeners = [
|
|||||||
AccountEventsTracker,
|
AccountEventsTracker,
|
||||||
ExpenseEventsTracker,
|
ExpenseEventsTracker,
|
||||||
AuthenticationEventsTracker,
|
AuthenticationEventsTracker,
|
||||||
ItemEventsTracker
|
ItemEventsTracker,
|
||||||
|
CustomerEventsTracker,
|
||||||
|
VendorEventsTracker,
|
||||||
|
ManualJournalEventsTracker,
|
||||||
|
BankRuleEventsTracker,
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user