Compare commits

...

2 Commits

Author SHA1 Message Date
standardci
67835ba0c0 chore(release): publish new version
- @standardnotes/analytics@2.10.3
2022-11-16 11:34:16 +00:00
Karol Sójko
fe1b2a0e07 fix(analytics): exclude five year plans from mrr stats 2022-11-16 12:32:22 +01:00
5 changed files with 23 additions and 13 deletions

View File

@@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [2.10.3](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.10.2...@standardnotes/analytics@2.10.3) (2022-11-16)
### Bug Fixes
* **analytics:** exclude five year plans from mrr stats ([fe1b2a0](https://github.com/standardnotes/server/commit/fe1b2a0e0744417e592f3f61f42610765b416ce6))
## [2.10.2](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.10.1...@standardnotes/analytics@2.10.2) (2022-11-14)
### Bug Fixes

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/analytics",
"version": "2.10.2",
"version": "2.10.3",
"engines": {
"node": ">=18.0.0 <19.0.0"
},

View File

@@ -4,6 +4,6 @@ import { RevenueModification } from './RevenueModification'
export interface RevenueModificationRepositoryInterface {
findLastByUserUuid(userUuid: Uuid): Promise<RevenueModification | null>
sumMRRDiff(dto: { planName?: string; billingFrequency?: number }): Promise<number>
sumMRRDiff(dto: { billingFrequencies: number[]; planNames?: string[] }): Promise<number>
save(revenueModification: RevenueModification): Promise<RevenueModification>
}

View File

@@ -20,7 +20,9 @@ export class CalculateMonthlyRecurringRevenue implements DomainUseCaseInterface<
) {}
async execute(_dto: CalculateMonthlyRecurringRevenueDTO): Promise<Result<MonthlyRevenue>> {
const mrrDiff = await this.revenueModificationRepository.sumMRRDiff({})
const mrrDiff = await this.revenueModificationRepository.sumMRRDiff({
billingFrequencies: [SubscriptionBillingFrequency.Annual, SubscriptionBillingFrequency.Monthly],
})
await this.statisticsStore.setMeasure(StatisticsMeasure.MRR, mrrDiff, [
Period.Today,
@@ -29,7 +31,7 @@ export class CalculateMonthlyRecurringRevenue implements DomainUseCaseInterface<
])
const monthlyPlansMrrDiff = await this.revenueModificationRepository.sumMRRDiff({
billingFrequency: SubscriptionBillingFrequency.Monthly,
billingFrequencies: [SubscriptionBillingFrequency.Monthly],
})
await this.statisticsStore.setMeasure(StatisticsMeasure.MonthlyPlansMRR, monthlyPlansMrrDiff, [
@@ -39,7 +41,7 @@ export class CalculateMonthlyRecurringRevenue implements DomainUseCaseInterface<
])
const annualPlansMrrDiff = await this.revenueModificationRepository.sumMRRDiff({
billingFrequency: SubscriptionBillingFrequency.Annual,
billingFrequencies: [SubscriptionBillingFrequency.Annual],
})
await this.statisticsStore.setMeasure(StatisticsMeasure.AnnualPlansMRR, annualPlansMrrDiff, [
@@ -49,7 +51,7 @@ export class CalculateMonthlyRecurringRevenue implements DomainUseCaseInterface<
])
const fiveYearPlansMrrDiff = await this.revenueModificationRepository.sumMRRDiff({
billingFrequency: SubscriptionBillingFrequency.FiveYear,
billingFrequencies: [SubscriptionBillingFrequency.FiveYear],
})
await this.statisticsStore.setMeasure(StatisticsMeasure.FiveYearPlansMRR, fiveYearPlansMrrDiff, [
@@ -59,7 +61,8 @@ export class CalculateMonthlyRecurringRevenue implements DomainUseCaseInterface<
])
const proPlansMrrDiff = await this.revenueModificationRepository.sumMRRDiff({
planName: SubscriptionName.ProPlan,
planNames: [SubscriptionName.ProPlan],
billingFrequencies: [SubscriptionBillingFrequency.Annual, SubscriptionBillingFrequency.Monthly],
})
await this.statisticsStore.setMeasure(StatisticsMeasure.ProPlansMRR, proPlansMrrDiff, [
@@ -69,7 +72,8 @@ export class CalculateMonthlyRecurringRevenue implements DomainUseCaseInterface<
])
const plusPlansMrrDiff = await this.revenueModificationRepository.sumMRRDiff({
planName: SubscriptionName.PlusPlan,
planNames: [SubscriptionName.PlusPlan],
billingFrequencies: [SubscriptionBillingFrequency.Annual, SubscriptionBillingFrequency.Monthly],
})
await this.statisticsStore.setMeasure(StatisticsMeasure.PlusPlansMRR, plusPlansMrrDiff, [

View File

@@ -16,14 +16,14 @@ export class MySQLRevenueModificationRepository implements RevenueModificationRe
private revenueModificationMap: MapInterface<RevenueModification, TypeORMRevenueModification>,
) {}
async sumMRRDiff(dto: { planName?: string; billingFrequency?: number }): Promise<number> {
async sumMRRDiff(dto: { billingFrequencies: number[]; planNames?: string[] }): Promise<number> {
const query = this.ormRepository.createQueryBuilder().select('sum(new_mrr - previous_mrr)', 'mrrDiff')
if (dto.planName !== undefined) {
query.where('subscription_plan = :planName', { planName: dto.planName })
if (dto.billingFrequencies.length > 0) {
query.where('billing_frequency IN (:...billingFrequencies)', { billingFrequencies: dto.billingFrequencies })
}
if (dto.billingFrequency !== undefined) {
query.where('billing_frequency = :billingFrequency', { billingFrequency: dto.billingFrequency })
if (dto.planNames && dto.planNames.length > 0) {
query.andWhere('subscription_plan IN (:...planNames)', { planNames: dto.planNames })
}
const result = await query.getRawOne()