fix(analytics): add persisting mrr for this month and this year as well

This commit is contained in:
Karol Sójko 2022-11-10 11:41:19 +01:00
parent 37a5cb347d
commit 8df0482eb4
No known key found for this signature in database
GPG key ID: A50543BF560BDEB0
2 changed files with 10 additions and 2 deletions

View file

@ -24,6 +24,10 @@ describe('CalculateMonthlyRecurringRevenue', () => {
it('should calculate the MRR diff and persist it as a statistic', async () => {
await createUseCase().execute({})
expect(statisticsStore.setMeasure).toHaveBeenCalledWith(StatisticsMeasure.MRR, 123.45, [Period.Today])
expect(statisticsStore.setMeasure).toHaveBeenCalledWith(StatisticsMeasure.MRR, 123.45, [
Period.Today,
Period.ThisMonth,
Period.ThisYear,
])
})
})

View file

@ -20,7 +20,11 @@ export class CalculateMonthlyRecurringRevenue implements DomainUseCaseInterface<
async execute(_dto: CalculateMonthlyRecurringRevenueDTO): Promise<Result<MonthlyRevenue>> {
const mrrDiff = await this.revenueModificationRepository.sumMRRDiff()
await this.statisticsStore.setMeasure(StatisticsMeasure.MRR, mrrDiff, [Period.Today])
await this.statisticsStore.setMeasure(StatisticsMeasure.MRR, mrrDiff, [
Period.Today,
Period.ThisMonth,
Period.ThisYear,
])
return MonthlyRevenue.create(mrrDiff)
}