feat(auth): add tracking total customers count

This commit is contained in:
Karol Sójko
2022-09-30 13:47:33 +02:00
parent 27cfd0ccf6
commit 8a98f746eb
15 changed files with 122 additions and 5 deletions
@@ -1,4 +1,5 @@
import { Uuid } from '@standardnotes/common'
import { TimerInterface } from '@standardnotes/time'
import { inject, injectable } from 'inversify'
import { Repository } from 'typeorm'
import TYPES from '../../Bootstrap/Types'
@@ -12,8 +13,18 @@ export class MySQLUserSubscriptionRepository implements UserSubscriptionReposito
constructor(
@inject(TYPES.ORMUserSubscriptionRepository)
private ormRepository: Repository<UserSubscription>,
@inject(TYPES.Timer) private timer: TimerInterface,
) {}
async countActiveSubscriptions(): Promise<number> {
return await this.ormRepository
.createQueryBuilder()
.select('user_uuid')
.distinct()
.where('ends_at > :timestamp', { timestamp: this.timer.getTimestampInMicroseconds() })
.getCount()
}
async findByUserUuid(userUuid: string): Promise<UserSubscription[]> {
return await this.ormRepository
.createQueryBuilder()