diff --git a/apps/api/src/services/data-provider/data-provider.service.ts b/apps/api/src/services/data-provider/data-provider.service.ts index 9a468f10e..c493ac4d1 100644 --- a/apps/api/src/services/data-provider/data-provider.service.ts +++ b/apps/api/src/services/data-provider/data-provider.service.ts @@ -9,6 +9,7 @@ import { import { MarketDataService } from '@ghostfolio/api/services/market-data/market-data.service'; import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; import { PropertyService } from '@ghostfolio/api/services/property/property.service'; +import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service'; import { DEFAULT_CURRENCY, DERIVED_CURRENCIES, @@ -36,7 +37,8 @@ export class DataProviderService { private readonly marketDataService: MarketDataService, private readonly prismaService: PrismaService, private readonly propertyService: PropertyService, - private readonly redisCacheService: RedisCacheService + private readonly redisCacheService: RedisCacheService, + private readonly symbolProfileService: SymbolProfileService ) { this.initialize(); } @@ -46,6 +48,26 @@ export class DataProviderService { ((await this.propertyService.getByKey(PROPERTY_DATA_SOURCE_MAPPING)) as { [dataProviderName: string]: string; }) ?? {}; + + const withSubscription = + await this.symbolProfileService.getSymbolProfilesWithSubscription(true); + console.log('withSubscription', withSubscription.length); + + // const vwrl = withSubscription.find(({ symbol }) => { + // return symbol === 'VWRL.SW'; + // }); + + // console.log({ vwrl }); + + const withoutSubscription = + await this.symbolProfileService.getSymbolProfilesWithSubscription(false); + console.log('withoutSubscription', withoutSubscription.length); + + console.log( + 'Total: ', + withSubscription.length + withoutSubscription.length, + await this.prismaService.symbolProfile.count() + ); } public async checkQuote(dataSource: DataSource) { diff --git a/apps/api/src/services/symbol-profile/symbol-profile.service.ts b/apps/api/src/services/symbol-profile/symbol-profile.service.ts index 1d7ea556b..ea66c388e 100644 --- a/apps/api/src/services/symbol-profile/symbol-profile.service.ts +++ b/apps/api/src/services/symbol-profile/symbol-profile.service.ts @@ -91,6 +91,35 @@ export class SymbolProfileService { }); } + public async getSymbolProfilesWithSubscription(withSubscription = true) { + return this.prismaService.symbolProfile.findMany({ + include: { + Order: { + include: { + User: true + } + } + }, + where: { + Order: withSubscription + ? { + some: { + User: { + Subscription: { some: { expiresAt: { gt: new Date() } } } + } + } + } + : { + every: { + User: { + Subscription: { none: { expiresAt: { gt: new Date() } } } + } + } + } + } + }); + } + public updateSymbolProfile({ assetClass, assetSubClass,