mirror of
https://github.com/standardnotes/server
synced 2026-07-14 09:01:33 -04:00
35 lines
1.6 KiB
TypeScript
35 lines
1.6 KiB
TypeScript
import { DomainEventHandlerInterface, SubscriptionExpiredEvent } from '@standardnotes/domain-events'
|
|
import { inject, injectable } from 'inversify'
|
|
|
|
import TYPES from '../../Bootstrap/Types'
|
|
import { AnalyticsActivity } from '../Analytics/AnalyticsActivity'
|
|
import { AnalyticsStoreInterface } from '../Analytics/AnalyticsStoreInterface'
|
|
import { StatisticsMeasure } from '../Statistics/StatisticsMeasure'
|
|
import { StatisticsStoreInterface } from '../Statistics/StatisticsStoreInterface'
|
|
import { Period } from '../Time/Period'
|
|
import { GetUserAnalyticsId } from '../UseCase/GetUserAnalyticsId/GetUserAnalyticsId'
|
|
|
|
@injectable()
|
|
export class SubscriptionExpiredEventHandler implements DomainEventHandlerInterface {
|
|
constructor(
|
|
@inject(TYPES.GetUserAnalyticsId) private getUserAnalyticsId: GetUserAnalyticsId,
|
|
@inject(TYPES.AnalyticsStore) private analyticsStore: AnalyticsStoreInterface,
|
|
@inject(TYPES.StatisticsStore) private statisticsStore: StatisticsStoreInterface,
|
|
) {}
|
|
|
|
async handle(event: SubscriptionExpiredEvent): Promise<void> {
|
|
const { analyticsId } = await this.getUserAnalyticsId.execute({ userEmail: event.payload.userEmail })
|
|
await this.analyticsStore.markActivity(
|
|
[AnalyticsActivity.SubscriptionExpired, AnalyticsActivity.ExistingCustomersChurn],
|
|
analyticsId,
|
|
[Period.Today, Period.ThisWeek, Period.ThisMonth],
|
|
)
|
|
|
|
await this.statisticsStore.setMeasure(
|
|
StatisticsMeasure.TotalCustomers,
|
|
event.payload.totalActiveSubscriptionsCount,
|
|
[Period.Today, Period.ThisWeek, Period.ThisMonth, Period.ThisYear],
|
|
)
|
|
}
|
|
}
|