Feature/Add dataProviderGhostfolioDailyRequests to Analytics (#4001)
* Add dataProviderGhostfolioDailyRequests to Analytics
This commit is contained in:
parent
53ae0d8aa7
commit
10e725b51a
@ -37,7 +37,7 @@ import { UserWithSettings } from '@ghostfolio/common/types';
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
import { Prisma, Role, User } from '@prisma/client';
|
import { Prisma, Role, User } from '@prisma/client';
|
||||||
import { differenceInDays } from 'date-fns';
|
import { differenceInDays, subDays } from 'date-fns';
|
||||||
import { sortBy, without } from 'lodash';
|
import { sortBy, without } from 'lodash';
|
||||||
|
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
@ -60,6 +60,13 @@ export class UserService {
|
|||||||
return this.prismaService.user.count(args);
|
return this.prismaService.user.count(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public createAccessToken(password: string, salt: string): string {
|
||||||
|
const hash = crypto.createHmac('sha512', salt);
|
||||||
|
hash.update(password);
|
||||||
|
|
||||||
|
return hash.digest('hex');
|
||||||
|
}
|
||||||
|
|
||||||
public async getUser(
|
public async getUser(
|
||||||
{ Account, id, permissions, Settings, subscription }: UserWithSettings,
|
{ Account, id, permissions, Settings, subscription }: UserWithSettings,
|
||||||
aLocale = locale
|
aLocale = locale
|
||||||
@ -358,13 +365,6 @@ export class UserService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public createAccessToken(password: string, salt: string): string {
|
|
||||||
const hash = crypto.createHmac('sha512', salt);
|
|
||||||
hash.update(password);
|
|
||||||
|
|
||||||
return hash.digest('hex');
|
|
||||||
}
|
|
||||||
|
|
||||||
public async createUser({
|
public async createUser({
|
||||||
data
|
data
|
||||||
}: {
|
}: {
|
||||||
@ -426,17 +426,6 @@ export class UserService {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateUser(params: {
|
|
||||||
where: Prisma.UserWhereUniqueInput;
|
|
||||||
data: Prisma.UserUpdateInput;
|
|
||||||
}): Promise<User> {
|
|
||||||
const { where, data } = params;
|
|
||||||
return this.prismaService.user.update({
|
|
||||||
data,
|
|
||||||
where
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public async deleteUser(where: Prisma.UserWhereUniqueInput): Promise<User> {
|
public async deleteUser(where: Prisma.UserWhereUniqueInput): Promise<User> {
|
||||||
try {
|
try {
|
||||||
await this.prismaService.access.deleteMany({
|
await this.prismaService.access.deleteMany({
|
||||||
@ -473,6 +462,32 @@ export class UserService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async resetAnalytics() {
|
||||||
|
return this.prismaService.analytics.updateMany({
|
||||||
|
data: {
|
||||||
|
dataProviderGhostfolioDailyRequests: 0
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
updatedAt: {
|
||||||
|
gte: subDays(new Date(), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateUser({
|
||||||
|
data,
|
||||||
|
where
|
||||||
|
}: {
|
||||||
|
data: Prisma.UserUpdateInput;
|
||||||
|
where: Prisma.UserWhereUniqueInput;
|
||||||
|
}): Promise<User> {
|
||||||
|
return this.prismaService.user.update({
|
||||||
|
data,
|
||||||
|
where
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public async updateUserSetting({
|
public async updateUserSetting({
|
||||||
emitPortfolioChangedEvent,
|
emitPortfolioChangedEvent,
|
||||||
userId,
|
userId,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { UserService } from '@ghostfolio/api/app/user/user.service';
|
||||||
import {
|
import {
|
||||||
DATA_GATHERING_QUEUE_PRIORITY_LOW,
|
DATA_GATHERING_QUEUE_PRIORITY_LOW,
|
||||||
GATHER_ASSET_PROFILE_PROCESS,
|
GATHER_ASSET_PROFILE_PROCESS,
|
||||||
@ -9,6 +10,7 @@ import { getAssetProfileIdentifier } from '@ghostfolio/common/helper';
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Cron, CronExpression } from '@nestjs/schedule';
|
import { Cron, CronExpression } from '@nestjs/schedule';
|
||||||
|
|
||||||
|
import { ConfigurationService } from './configuration/configuration.service';
|
||||||
import { ExchangeRateDataService } from './exchange-rate-data/exchange-rate-data.service';
|
import { ExchangeRateDataService } from './exchange-rate-data/exchange-rate-data.service';
|
||||||
import { PropertyService } from './property/property.service';
|
import { PropertyService } from './property/property.service';
|
||||||
import { DataGatheringService } from './queues/data-gathering/data-gathering.service';
|
import { DataGatheringService } from './queues/data-gathering/data-gathering.service';
|
||||||
@ -19,10 +21,12 @@ export class CronService {
|
|||||||
private static readonly EVERY_SUNDAY_AT_LUNCH_TIME = '0 12 * * 0';
|
private static readonly EVERY_SUNDAY_AT_LUNCH_TIME = '0 12 * * 0';
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
|
private readonly configurationService: ConfigurationService,
|
||||||
private readonly dataGatheringService: DataGatheringService,
|
private readonly dataGatheringService: DataGatheringService,
|
||||||
private readonly exchangeRateDataService: ExchangeRateDataService,
|
private readonly exchangeRateDataService: ExchangeRateDataService,
|
||||||
private readonly propertyService: PropertyService,
|
private readonly propertyService: PropertyService,
|
||||||
private readonly twitterBotService: TwitterBotService
|
private readonly twitterBotService: TwitterBotService,
|
||||||
|
private readonly userService: UserService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Cron(CronExpression.EVERY_HOUR)
|
@Cron(CronExpression.EVERY_HOUR)
|
||||||
@ -42,6 +46,13 @@ export class CronService {
|
|||||||
this.twitterBotService.tweetFearAndGreedIndex();
|
this.twitterBotService.tweetFearAndGreedIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)
|
||||||
|
public async runEveryDayAtMidnight() {
|
||||||
|
if (this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')) {
|
||||||
|
this.userService.resetAnalytics();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Cron(CronService.EVERY_SUNDAY_AT_LUNCH_TIME)
|
@Cron(CronService.EVERY_SUNDAY_AT_LUNCH_TIME)
|
||||||
public async runEverySundayAtTwelvePm() {
|
public async runEverySundayAtTwelvePm() {
|
||||||
if (await this.isDataGatheringEnabled()) {
|
if (await this.isDataGatheringEnabled()) {
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Analytics" ADD COLUMN "dataProviderGhostfolioDailyRequests" INTEGER NOT NULL DEFAULT 0;
|
@ -67,6 +67,7 @@ model AccountBalance {
|
|||||||
model Analytics {
|
model Analytics {
|
||||||
activityCount Int @default(0)
|
activityCount Int @default(0)
|
||||||
country String?
|
country String?
|
||||||
|
dataProviderGhostfolioDailyRequests Int @default(0)
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
userId String @id
|
userId String @id
|
||||||
User User @relation(fields: [userId], onDelete: Cascade, references: [id])
|
User User @relation(fields: [userId], onDelete: Cascade, references: [id])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user