|
|
@ -1,3 +1,5 @@ |
|
|
|
import { SubscriptionService } from '@ghostfolio/api/app/subscription/subscription.service'; |
|
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; |
|
|
|
import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; |
|
|
|
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; |
|
|
|
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; |
|
|
@ -9,9 +11,11 @@ import { differenceInDays } from 'date-fns'; |
|
|
|
@Injectable() |
|
|
|
export class AdminService { |
|
|
|
public constructor( |
|
|
|
private readonly configurationService: ConfigurationService, |
|
|
|
private readonly dataGatheringService: DataGatheringService, |
|
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
|
private readonly prismaService: PrismaService |
|
|
|
private readonly prismaService: PrismaService, |
|
|
|
private readonly subscriptionService: SubscriptionService |
|
|
|
) {} |
|
|
|
|
|
|
|
public async get(): Promise<AdminData> { |
|
|
@ -107,7 +111,8 @@ export class AdminService { |
|
|
|
} |
|
|
|
}, |
|
|
|
createdAt: true, |
|
|
|
id: true |
|
|
|
id: true, |
|
|
|
Subscription: true |
|
|
|
}, |
|
|
|
take: 30, |
|
|
|
where: { |
|
|
@ -118,16 +123,23 @@ export class AdminService { |
|
|
|
}); |
|
|
|
|
|
|
|
return usersWithAnalytics.map( |
|
|
|
({ _count, alias, Analytics, createdAt, id }) => { |
|
|
|
({ _count, alias, Analytics, createdAt, id, Subscription }) => { |
|
|
|
const daysSinceRegistration = |
|
|
|
differenceInDays(new Date(), createdAt) + 1; |
|
|
|
const engagement = Analytics.activityCount / daysSinceRegistration; |
|
|
|
|
|
|
|
const subscription = this.configurationService.get( |
|
|
|
'ENABLE_FEATURE_SUBSCRIPTION' |
|
|
|
) |
|
|
|
? this.subscriptionService.getSubscription(Subscription) |
|
|
|
: undefined; |
|
|
|
|
|
|
|
return { |
|
|
|
alias, |
|
|
|
createdAt, |
|
|
|
engagement, |
|
|
|
id, |
|
|
|
subscription, |
|
|
|
accountCount: _count.Account || 0, |
|
|
|
lastActivity: Analytics.updatedAt, |
|
|
|
transactionCount: _count.Order || 0 |
|
|
|