feat(analytics): add calculating monthly recurring revenue

This commit is contained in:
Karol Sójko
2022-11-10 11:33:46 +01:00
parent eacd2abc00
commit 77e50655f6
17 changed files with 179 additions and 444 deletions
@@ -17,6 +17,19 @@ export class MySQLRevenueModificationRepository implements RevenueModificationRe
private revenueModificationMap: MapInterface<RevenueModification, TypeORMRevenueModification>,
) {}
async sumMRRDiff(): Promise<number> {
const result = await this.ormRepository
.createQueryBuilder()
.select('sum(new_mrr - previous_mrr)', 'mrrDiff')
.getRawOne()
if (result === undefined) {
return 0
}
return +(+result.mrrDiff).toFixed(2)
}
async findLastByUserUuid(userUuid: Uuid): Promise<RevenueModification | null> {
const persistence = await this.ormRepository
.createQueryBuilder()