|
|
|
@ -27,12 +27,13 @@ import {
|
|
|
|
|
} from '@ghostfolio/common/interfaces';
|
|
|
|
|
import { MarketDataPreset } from '@ghostfolio/common/types';
|
|
|
|
|
|
|
|
|
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
|
|
|
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
|
|
|
|
|
import {
|
|
|
|
|
AssetClass,
|
|
|
|
|
AssetSubClass,
|
|
|
|
|
DataSource,
|
|
|
|
|
Prisma,
|
|
|
|
|
PrismaClient,
|
|
|
|
|
Property,
|
|
|
|
|
SymbolProfile
|
|
|
|
|
} from '@prisma/client';
|
|
|
|
@ -212,8 +213,11 @@ export class AdminService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const extendedPrismaClient = this.getExtendedPrismaClient();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let [assetProfiles, count] = await Promise.all([
|
|
|
|
|
this.prismaService.symbolProfile.findMany({
|
|
|
|
|
extendedPrismaClient.symbolProfile.findMany({
|
|
|
|
|
orderBy,
|
|
|
|
|
skip,
|
|
|
|
|
take,
|
|
|
|
@ -229,6 +233,7 @@ export class AdminService {
|
|
|
|
|
currency: true,
|
|
|
|
|
dataSource: true,
|
|
|
|
|
id: true,
|
|
|
|
|
isUsedByUsersWithSubscription: true,
|
|
|
|
|
name: true,
|
|
|
|
|
Order: {
|
|
|
|
|
orderBy: [{ date: 'asc' }],
|
|
|
|
@ -243,8 +248,9 @@ export class AdminService {
|
|
|
|
|
this.prismaService.symbolProfile.count({ where })
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
let marketData: AdminMarketDataItem[] = assetProfiles.map(
|
|
|
|
|
({
|
|
|
|
|
let marketData: AdminMarketDataItem[] = await Promise.all(
|
|
|
|
|
assetProfiles.map(
|
|
|
|
|
async ({
|
|
|
|
|
_count,
|
|
|
|
|
assetClass,
|
|
|
|
|
assetSubClass,
|
|
|
|
@ -253,12 +259,15 @@ export class AdminService {
|
|
|
|
|
currency,
|
|
|
|
|
dataSource,
|
|
|
|
|
id,
|
|
|
|
|
isUsedByUsersWithSubscription,
|
|
|
|
|
name,
|
|
|
|
|
Order,
|
|
|
|
|
sectors,
|
|
|
|
|
symbol
|
|
|
|
|
}) => {
|
|
|
|
|
const countriesCount = countries ? Object.keys(countries).length : 0;
|
|
|
|
|
const countriesCount = countries
|
|
|
|
|
? Object.keys(countries).length
|
|
|
|
|
: 0;
|
|
|
|
|
const marketDataItemCount =
|
|
|
|
|
marketDataItems.find((marketDataItem) => {
|
|
|
|
|
return (
|
|
|
|
@ -281,9 +290,11 @@ export class AdminService {
|
|
|
|
|
marketDataItemCount,
|
|
|
|
|
sectorsCount,
|
|
|
|
|
activitiesCount: _count.Order,
|
|
|
|
|
date: Order?.[0]?.date
|
|
|
|
|
date: Order?.[0]?.date,
|
|
|
|
|
isUsedByUsersWithSubscription: await isUsedByUsersWithSubscription
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (presetId) {
|
|
|
|
@ -304,6 +315,11 @@ export class AdminService {
|
|
|
|
|
count,
|
|
|
|
|
marketData
|
|
|
|
|
};
|
|
|
|
|
} finally {
|
|
|
|
|
await extendedPrismaClient.$disconnect();
|
|
|
|
|
|
|
|
|
|
Logger.debug('Disconnect extended prisma client', 'AdminService');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async getMarketDataBySymbol({
|
|
|
|
@ -431,6 +447,52 @@ export class AdminService {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getExtendedPrismaClient() {
|
|
|
|
|
Logger.debug('Connect extended prisma client', 'AdminService');
|
|
|
|
|
|
|
|
|
|
const symbolProfileExtension = Prisma.defineExtension((client) => {
|
|
|
|
|
return client.$extends({
|
|
|
|
|
result: {
|
|
|
|
|
symbolProfile: {
|
|
|
|
|
isUsedByUsersWithSubscription: {
|
|
|
|
|
compute: async ({ id }) => {
|
|
|
|
|
const { _count } =
|
|
|
|
|
await this.prismaService.symbolProfile.findUnique({
|
|
|
|
|
select: {
|
|
|
|
|
_count: {
|
|
|
|
|
select: {
|
|
|
|
|
Order: {
|
|
|
|
|
where: {
|
|
|
|
|
User: {
|
|
|
|
|
Subscription: {
|
|
|
|
|
some: {
|
|
|
|
|
expiresAt: {
|
|
|
|
|
gt: new Date()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
where: {
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return _count.Order > 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return new PrismaClient().$extends(symbolProfileExtension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async getMarketDataForCurrencies(): Promise<AdminMarketData> {
|
|
|
|
|
const marketDataItems = await this.prismaService.marketData.groupBy({
|
|
|
|
|
_count: true,
|
|
|
|
|