refactor: events tracker to nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-01-08 11:59:55 +02:00
parent fdfb766587
commit 52362a43ab
33 changed files with 1417 additions and 10 deletions

View File

@@ -0,0 +1,57 @@
import { ITransactionsLockingPartialUnlocked } from '@/interfaces';
import {
SUBSCRIPTION_CANCELLED,
SUBSCRIPTION_PAYMENT_FAILED,
SUBSCRIPTION_PAYMENT_SUCCEED,
SUBSCRIPTION_PLAN_CHANGED,
SUBSCRIPTION_RESUMED,
} from '../event-tracker';
import { OnEvent } from '@nestjs/event-emitter';
import { Injectable } from '@nestjs/common';
import { EventTrackerService } from '../EventTracker.service';
import { events } from '@/common/events/events';
@Injectable()
export class TransactionsLockingEventsTracker {
constructor(public readonly posthog: EventTrackerService) {}
@OnEvent(events.subscription.onSubscriptionResumed)
public handleSubscriptionResumedEvent() {
this.posthog.trackEvent({
event: SUBSCRIPTION_RESUMED,
properties: {},
});
}
@OnEvent(events.subscription.onSubscriptionCancelled)
public handleSubscriptionCancelledEvent() {
this.posthog.trackEvent({
event: SUBSCRIPTION_CANCELLED,
properties: {},
});
}
@OnEvent(events.subscription.onSubscriptionPlanChanged)
public handleSubscriptionPlanChangedEvent() {
this.posthog.trackEvent({
event: SUBSCRIPTION_PLAN_CHANGED,
properties: {},
});
}
@OnEvent(events.subscription.onSubscriptionPaymentFailed)
public handleSubscriptionPaymentFailedEvent() {
this.posthog.trackEvent({
event: SUBSCRIPTION_PAYMENT_FAILED,
properties: {},
});
}
@OnEvent(events.subscription.onSubscriptionPaymentSucceed)
public handleSubscriptionPaymentSucceed() {
this.posthog.trackEvent({
event: SUBSCRIPTION_PAYMENT_SUCCEED,
properties: {},
});
}
}