From 308b218487c127d203532ac5c7e83f0526132413 Mon Sep 17 00:00:00 2001 From: Valentin Zickner <3200232+vzickner@users.noreply.github.com> Date: Sat, 14 Aug 2021 16:55:40 +0200 Subject: [PATCH] introduce basic module structure for data provider (#278) * introduce basic module structure for data provider * introduce DataGatheringModule * introduce ExchangeRateDataModule * introduce ImpersonationModule * move RulesService * cleanup portfolio module * Sort imports Co-authored-by: Valentin Zickner Co-authored-by: Thomas <4159106+dtslvr@users.noreply.github.com> --- apps/api/src/app/account/account.module.ts | 38 ++++++-------- apps/api/src/app/admin/admin.module.ts | 35 +++++-------- apps/api/src/app/app.module.ts | 38 +++++--------- apps/api/src/app/auth/auth.module.ts | 2 +- apps/api/src/app/auth/auth.service.ts | 2 +- apps/api/src/app/auth/jwt.strategy.ts | 3 +- apps/api/src/app/auth/web-auth.service.ts | 2 +- apps/api/src/app/cache/cache.controller.ts | 5 +- apps/api/src/app/cache/cache.module.ts | 6 +-- apps/api/src/app/core/core.module.ts | 30 ----------- .../interfaces/transaction-point.interface.ts | 6 --- .../app/experimental/experimental.module.ts | 35 +++++-------- .../app/experimental/experimental.service.ts | 6 +-- apps/api/src/app/export/export.module.ts | 33 +++++------- apps/api/src/app/import/import.module.ts | 34 +++++-------- apps/api/src/app/info/info.module.ts | 2 +- apps/api/src/app/order/order.module.ts | 42 +++++++--------- apps/api/src/app/order/order.service.ts | 3 +- .../current-rate.service.spec.ts | 4 +- .../current-rate.service.ts | 8 +-- .../interfaces/current-positions.interface.ts | 0 .../interfaces/date-query.interface.ts | 0 .../interfaces/get-value-object.interface.ts | 0 .../interfaces/get-value-params.interface.ts | 0 .../interfaces/get-values-params.interface.ts | 3 +- .../interfaces/portfolio-order.interface.ts | 0 .../interfaces/timeline-period.interface.ts | 0 .../timeline-specification.interface.ts | 0 .../transaction-point-symbol.interface.ts | 0 .../interfaces/transaction-point.interface.ts | 6 +++ .../market-data.service.ts | 0 .../portfolio-calculator.spec.ts | 19 +++---- .../portfolio-calculator.ts | 23 +++++---- .../src/app/portfolio/portfolio.controller.ts | 2 +- .../api/src/app/portfolio/portfolio.module.ts | 50 ++++++++----------- .../src/app/portfolio/portfolio.service.ts | 14 +++--- .../portfolio}/rules.service.ts | 3 +- apps/api/src/app/symbol/symbol.module.ts | 23 ++------- apps/api/src/app/symbol/symbol.service.ts | 2 +- apps/api/src/models/rule.ts | 2 +- .../base-currency-current-investment.ts | 2 +- .../base-currency-initial-investment.ts | 2 +- .../current-investment.ts | 2 +- .../initial-investment.ts | 2 +- apps/api/src/services/configuration.module.ts | 8 +++ .../api/src/services/data-gathering.module.ts | 12 +++++ .../src/services/data-gathering.service.ts | 2 +- .../alpha-vantage/alpha-vantage.service.ts | 2 +- .../data-provider/data-provider.module.ts | 22 ++++++++ .../data-provider.service.ts | 22 ++++---- .../ghostfolio-scraper-api.service.ts | 2 +- .../rakuten-rapid-api.service.ts | 4 +- .../src/services/exchange-rate-data.module.ts | 10 ++++ .../services/exchange-rate-data.service.ts | 2 +- apps/api/src/services/impersonation.module.ts | 10 ++++ apps/api/src/services/prisma.module.ts | 8 +++ 56 files changed, 270 insertions(+), 323 deletions(-) delete mode 100644 apps/api/src/app/core/core.module.ts delete mode 100644 apps/api/src/app/core/interfaces/transaction-point.interface.ts rename apps/api/src/app/{core => portfolio}/current-rate.service.spec.ts (96%) rename apps/api/src/app/{core => portfolio}/current-rate.service.ts (91%) rename apps/api/src/app/{core => portfolio}/interfaces/current-positions.interface.ts (100%) rename apps/api/src/app/{core => portfolio}/interfaces/date-query.interface.ts (100%) rename apps/api/src/app/{core => portfolio}/interfaces/get-value-object.interface.ts (100%) rename apps/api/src/app/{core => portfolio}/interfaces/get-value-params.interface.ts (100%) rename apps/api/src/app/{core => portfolio}/interfaces/get-values-params.interface.ts (69%) rename apps/api/src/app/{core => portfolio}/interfaces/portfolio-order.interface.ts (100%) rename apps/api/src/app/{core => portfolio}/interfaces/timeline-period.interface.ts (100%) rename apps/api/src/app/{core => portfolio}/interfaces/timeline-specification.interface.ts (100%) rename apps/api/src/app/{core => portfolio}/interfaces/transaction-point-symbol.interface.ts (100%) create mode 100644 apps/api/src/app/portfolio/interfaces/transaction-point.interface.ts rename apps/api/src/app/{core => portfolio}/market-data.service.ts (100%) rename apps/api/src/app/{core => portfolio}/portfolio-calculator.spec.ts (98%) rename apps/api/src/app/{core => portfolio}/portfolio-calculator.ts (95%) rename apps/api/src/{services => app/portfolio}/rules.service.ts (92%) create mode 100644 apps/api/src/services/configuration.module.ts create mode 100644 apps/api/src/services/data-gathering.module.ts create mode 100644 apps/api/src/services/data-provider/data-provider.module.ts rename apps/api/src/services/{ => data-provider}/data-provider.service.ts (91%) create mode 100644 apps/api/src/services/exchange-rate-data.module.ts create mode 100644 apps/api/src/services/impersonation.module.ts create mode 100644 apps/api/src/services/prisma.module.ts diff --git a/apps/api/src/app/account/account.module.ts b/apps/api/src/app/account/account.module.ts index bbd272978..1a3bb32e1 100644 --- a/apps/api/src/app/account/account.module.ts +++ b/apps/api/src/app/account/account.module.ts @@ -1,32 +1,24 @@ -import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; -import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; -import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; -import { ImpersonationService } from '@ghostfolio/api/services/impersonation.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; +import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module'; +import { ImpersonationModule } from '@ghostfolio/api/services/impersonation.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { Module } from '@nestjs/common'; -import { RedisCacheModule } from '../redis-cache/redis-cache.module'; import { AccountController } from './account.controller'; import { AccountService } from './account.service'; @Module({ - imports: [RedisCacheModule], + imports: [ + ConfigurationModule, + DataProviderModule, + ExchangeRateDataModule, + ImpersonationModule, + RedisCacheModule, + PrismaModule + ], controllers: [AccountController], - providers: [ - AccountService, - AlphaVantageService, - ConfigurationService, - DataProviderService, - ExchangeRateDataService, - GhostfolioScraperApiService, - ImpersonationService, - PrismaService, - RakutenRapidApiService, - YahooFinanceService - ] + providers: [AccountService] }) export class AccountModule {} diff --git a/apps/api/src/app/admin/admin.module.ts b/apps/api/src/app/admin/admin.module.ts index a78c435e3..fa2118e17 100644 --- a/apps/api/src/app/admin/admin.module.ts +++ b/apps/api/src/app/admin/admin.module.ts @@ -1,31 +1,22 @@ -import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; -import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; -import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering.module'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { Module } from '@nestjs/common'; import { AdminController } from './admin.controller'; import { AdminService } from './admin.service'; @Module({ - imports: [], + imports: [ + ConfigurationModule, + DataGatheringModule, + DataProviderModule, + ExchangeRateDataModule, + PrismaModule + ], controllers: [AdminController], - providers: [ - AdminService, - AlphaVantageService, - ConfigurationService, - DataGatheringService, - DataProviderService, - ExchangeRateDataService, - GhostfolioScraperApiService, - PrismaService, - RakutenRapidApiService, - YahooFinanceService - ] + providers: [AdminService] }) export class AdminModule {} diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index 8dff979e4..305284466 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -1,35 +1,30 @@ import { join } from 'path'; import { AuthDeviceModule } from '@ghostfolio/api/app/auth-device/auth-device.module'; +import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { CronService } from '@ghostfolio/api/services/cron.service'; +import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering.module'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { ScheduleModule } from '@nestjs/schedule'; import { ServeStaticModule } from '@nestjs/serve-static'; -import { ConfigurationService } from '../services/configuration.service'; -import { CronService } from '../services/cron.service'; -import { DataGatheringService } from '../services/data-gathering.service'; -import { DataProviderService } from '../services/data-provider.service'; -import { AlphaVantageService } from '../services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '../services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '../services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '../services/data-provider/yahoo-finance/yahoo-finance.service'; -import { ExchangeRateDataService } from '../services/exchange-rate-data.service'; -import { PrismaService } from '../services/prisma.service'; import { AccessModule } from './access/access.module'; import { AccountModule } from './account/account.module'; import { AdminModule } from './admin/admin.module'; import { AppController } from './app.controller'; import { AuthModule } from './auth/auth.module'; import { CacheModule } from './cache/cache.module'; -import { CoreModule } from './core/core.module'; import { ExperimentalModule } from './experimental/experimental.module'; import { ExportModule } from './export/export.module'; import { ImportModule } from './import/import.module'; import { InfoModule } from './info/info.module'; import { OrderModule } from './order/order.module'; import { PortfolioModule } from './portfolio/portfolio.module'; -import { RedisCacheModule } from './redis-cache/redis-cache.module'; import { SubscriptionModule } from './subscription/subscription.module'; import { SymbolModule } from './symbol/symbol.module'; import { UserModule } from './user/user.module'; @@ -43,13 +38,17 @@ import { UserModule } from './user/user.module'; AuthModule, CacheModule, ConfigModule.forRoot(), - CoreModule, + ConfigurationModule, + DataGatheringModule, + DataProviderModule, + ExchangeRateDataModule, ExperimentalModule, ExportModule, ImportModule, InfoModule, OrderModule, PortfolioModule, + PrismaModule, RedisCacheModule, ScheduleModule.forRoot(), ServeStaticModule.forRoot({ @@ -71,17 +70,6 @@ import { UserModule } from './user/user.module'; UserModule ], controllers: [AppController], - providers: [ - AlphaVantageService, - ConfigurationService, - CronService, - DataGatheringService, - DataProviderService, - ExchangeRateDataService, - GhostfolioScraperApiService, - PrismaService, - RakutenRapidApiService, - YahooFinanceService - ] + providers: [CronService] }) export class AppModule {} diff --git a/apps/api/src/app/auth/auth.module.ts b/apps/api/src/app/auth/auth.module.ts index 9b8ac4c39..673169307 100644 --- a/apps/api/src/app/auth/auth.module.ts +++ b/apps/api/src/app/auth/auth.module.ts @@ -1,11 +1,11 @@ import { AuthDeviceService } from '@ghostfolio/api/app/auth-device/auth-device.service'; import { WebAuthService } from '@ghostfolio/api/app/auth/web-auth.service'; +import { UserService } from '@ghostfolio/api/app/user/user.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { Module } from '@nestjs/common'; import { JwtModule } from '@nestjs/jwt'; -import { UserService } from '../user/user.service'; import { AuthController } from './auth.controller'; import { AuthService } from './auth.service'; import { GoogleStrategy } from './google.strategy'; diff --git a/apps/api/src/app/auth/auth.service.ts b/apps/api/src/app/auth/auth.service.ts index b7d334773..dbc5024b5 100644 --- a/apps/api/src/app/auth/auth.service.ts +++ b/apps/api/src/app/auth/auth.service.ts @@ -1,8 +1,8 @@ +import { UserService } from '@ghostfolio/api/app/user/user.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { Injectable, InternalServerErrorException } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; -import { UserService } from '../user/user.service'; import { ValidateOAuthLoginParams } from './interfaces/interfaces'; @Injectable() diff --git a/apps/api/src/app/auth/jwt.strategy.ts b/apps/api/src/app/auth/jwt.strategy.ts index 5fd1ec290..ee50e3b72 100644 --- a/apps/api/src/app/auth/jwt.strategy.ts +++ b/apps/api/src/app/auth/jwt.strategy.ts @@ -1,11 +1,10 @@ +import { UserService } from '@ghostfolio/api/app/user/user.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { Injectable, UnauthorizedException } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { ExtractJwt, Strategy } from 'passport-jwt'; -import { UserService } from '../user/user.service'; - @Injectable() export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') { public constructor( diff --git a/apps/api/src/app/auth/web-auth.service.ts b/apps/api/src/app/auth/web-auth.service.ts index 157f75e36..b0368748a 100644 --- a/apps/api/src/app/auth/web-auth.service.ts +++ b/apps/api/src/app/auth/web-auth.service.ts @@ -1,5 +1,6 @@ import { AuthDeviceDto } from '@ghostfolio/api/app/auth-device/auth-device.dto'; import { AuthDeviceService } from '@ghostfolio/api/app/auth-device/auth-device.service'; +import { UserService } from '@ghostfolio/api/app/user/user.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { RequestWithUser } from '@ghostfolio/common/types'; import { @@ -22,7 +23,6 @@ import { verifyAttestationResponse } from '@simplewebauthn/server'; -import { UserService } from '../user/user.service'; import { AssertionCredentialJSON, AttestationCredentialJSON diff --git a/apps/api/src/app/cache/cache.controller.ts b/apps/api/src/app/cache/cache.controller.ts index 23a358d20..21aa5a8b6 100644 --- a/apps/api/src/app/cache/cache.controller.ts +++ b/apps/api/src/app/cache/cache.controller.ts @@ -1,11 +1,10 @@ +import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; +import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service'; import { RequestWithUser } from '@ghostfolio/common/types'; import { Controller, Inject, Post, UseGuards } from '@nestjs/common'; import { REQUEST } from '@nestjs/core'; import { AuthGuard } from '@nestjs/passport'; -import { RedisCacheService } from '../redis-cache/redis-cache.service'; -import { CacheService } from './cache.service'; - @Controller('cache') export class CacheController { public constructor( diff --git a/apps/api/src/app/cache/cache.module.ts b/apps/api/src/app/cache/cache.module.ts index 895c65d18..15e63e818 100644 --- a/apps/api/src/app/cache/cache.module.ts +++ b/apps/api/src/app/cache/cache.module.ts @@ -1,16 +1,16 @@ +import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; +import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; +import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { Module } from '@nestjs/common'; -import { RedisCacheModule } from '../redis-cache/redis-cache.module'; import { CacheController } from './cache.controller'; -import { CacheService } from './cache.service'; @Module({ imports: [RedisCacheModule], diff --git a/apps/api/src/app/core/core.module.ts b/apps/api/src/app/core/core.module.ts deleted file mode 100644 index 2ae0ebf93..000000000 --- a/apps/api/src/app/core/core.module.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; -import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; -import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; -import { Module } from '@nestjs/common'; - -import { CurrentRateService } from './current-rate.service'; -import { MarketDataService } from './market-data.service'; - -@Module({ - imports: [], - controllers: [], - providers: [ - AlphaVantageService, - ConfigurationService, - CurrentRateService, - DataProviderService, - ExchangeRateDataService, - GhostfolioScraperApiService, - MarketDataService, - PrismaService, - RakutenRapidApiService, - YahooFinanceService - ] -}) -export class CoreModule {} diff --git a/apps/api/src/app/core/interfaces/transaction-point.interface.ts b/apps/api/src/app/core/interfaces/transaction-point.interface.ts deleted file mode 100644 index eadc1e63f..000000000 --- a/apps/api/src/app/core/interfaces/transaction-point.interface.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { TransactionPointSymbol } from '@ghostfolio/api/app/core/interfaces/transaction-point-symbol.interface'; - -export interface TransactionPoint { - date: string; - items: TransactionPointSymbol[]; -} diff --git a/apps/api/src/app/experimental/experimental.module.ts b/apps/api/src/app/experimental/experimental.module.ts index 7394c70eb..59d0ffba9 100644 --- a/apps/api/src/app/experimental/experimental.module.ts +++ b/apps/api/src/app/experimental/experimental.module.ts @@ -1,34 +1,23 @@ import { AccountService } from '@ghostfolio/api/app/account/account.service'; import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; -import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; -import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; -import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; -import { RulesService } from '@ghostfolio/api/services/rules.service'; +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { Module } from '@nestjs/common'; import { ExperimentalController } from './experimental.controller'; import { ExperimentalService } from './experimental.service'; @Module({ - imports: [RedisCacheModule], + imports: [ + ConfigurationModule, + DataProviderModule, + ExchangeRateDataModule, + RedisCacheModule, + PrismaModule + ], controllers: [ExperimentalController], - providers: [ - AccountService, - AlphaVantageService, - ConfigurationService, - DataProviderService, - ExchangeRateDataService, - ExperimentalService, - GhostfolioScraperApiService, - PrismaService, - RakutenRapidApiService, - RulesService, - YahooFinanceService - ] + providers: [AccountService, ExperimentalService] }) export class ExperimentalModule {} diff --git a/apps/api/src/app/experimental/experimental.service.ts b/apps/api/src/app/experimental/experimental.service.ts index 79a4427d0..854f1cf58 100644 --- a/apps/api/src/app/experimental/experimental.service.ts +++ b/apps/api/src/app/experimental/experimental.service.ts @@ -1,8 +1,7 @@ import { AccountService } from '@ghostfolio/api/app/account/account.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; +import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service'; -import { RulesService } from '@ghostfolio/api/services/rules.service'; import { Injectable } from '@nestjs/common'; @Injectable() @@ -11,8 +10,7 @@ export class ExperimentalService { private readonly accountService: AccountService, private readonly dataProviderService: DataProviderService, private readonly exchangeRateDataService: ExchangeRateDataService, - private readonly prismaService: PrismaService, - private readonly rulesService: RulesService + private readonly prismaService: PrismaService ) {} public async getBenchmark(aSymbol: string) { diff --git a/apps/api/src/app/export/export.module.ts b/apps/api/src/app/export/export.module.ts index 2da4e566f..c30743d31 100644 --- a/apps/api/src/app/export/export.module.ts +++ b/apps/api/src/app/export/export.module.ts @@ -1,32 +1,23 @@ import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; -import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; -import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering.module'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { Module } from '@nestjs/common'; import { ExportController } from './export.controller'; import { ExportService } from './export.service'; @Module({ - imports: [RedisCacheModule], + imports: [ + ConfigurationModule, + DataGatheringModule, + DataProviderModule, + PrismaModule, + RedisCacheModule + ], controllers: [ExportController], - providers: [ - AlphaVantageService, - CacheService, - ConfigurationService, - DataGatheringService, - DataProviderService, - ExportService, - GhostfolioScraperApiService, - PrismaService, - RakutenRapidApiService, - YahooFinanceService - ] + providers: [CacheService, ExportService] }) export class ExportModule {} diff --git a/apps/api/src/app/import/import.module.ts b/apps/api/src/app/import/import.module.ts index 02efd6f51..c7533980d 100644 --- a/apps/api/src/app/import/import.module.ts +++ b/apps/api/src/app/import/import.module.ts @@ -1,34 +1,24 @@ import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; import { OrderService } from '@ghostfolio/api/app/order/order.service'; import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; -import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; -import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering.module'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { Module } from '@nestjs/common'; import { ImportController } from './import.controller'; import { ImportService } from './import.service'; @Module({ - imports: [RedisCacheModule], + imports: [ + ConfigurationModule, + DataGatheringModule, + DataProviderModule, + PrismaModule, + RedisCacheModule + ], controllers: [ImportController], - providers: [ - AlphaVantageService, - CacheService, - ConfigurationService, - DataGatheringService, - DataProviderService, - GhostfolioScraperApiService, - ImportService, - OrderService, - PrismaService, - RakutenRapidApiService, - YahooFinanceService - ] + providers: [CacheService, ImportService, OrderService] }) export class ImportModule {} diff --git a/apps/api/src/app/info/info.module.ts b/apps/api/src/app/info/info.module.ts index 6ff7b5729..71fae0fe2 100644 --- a/apps/api/src/app/info/info.module.ts +++ b/apps/api/src/app/info/info.module.ts @@ -1,7 +1,7 @@ import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; +import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; diff --git a/apps/api/src/app/order/order.module.ts b/apps/api/src/app/order/order.module.ts index 93bcd3cb3..83dec6f5b 100644 --- a/apps/api/src/app/order/order.module.ts +++ b/apps/api/src/app/order/order.module.ts @@ -1,34 +1,26 @@ -import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; -import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; -import { ImpersonationService } from '@ghostfolio/api/services/impersonation.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; +import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; +import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering.module'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { ImpersonationModule } from '@ghostfolio/api/services/impersonation.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { Module } from '@nestjs/common'; -import { CacheService } from '../cache/cache.service'; -import { RedisCacheModule } from '../redis-cache/redis-cache.module'; import { OrderController } from './order.controller'; import { OrderService } from './order.service'; @Module({ - imports: [RedisCacheModule], + imports: [ + ConfigurationModule, + DataGatheringModule, + DataProviderModule, + ImpersonationModule, + PrismaModule, + RedisCacheModule + ], controllers: [OrderController], - providers: [ - AlphaVantageService, - CacheService, - ConfigurationService, - DataGatheringService, - DataProviderService, - GhostfolioScraperApiService, - ImpersonationService, - OrderService, - PrismaService, - RakutenRapidApiService, - YahooFinanceService - ] + providers: [CacheService, OrderService], + exports: [OrderService] }) export class OrderModule {} diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 071b52f4c..ef9f9278c 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -1,3 +1,4 @@ +import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { OrderWithAccount } from '@ghostfolio/common/types'; @@ -5,8 +6,6 @@ import { Injectable } from '@nestjs/common'; import { DataSource, Order, Prisma } from '@prisma/client'; import { endOfToday, isAfter } from 'date-fns'; -import { CacheService } from '../cache/cache.service'; - @Injectable() export class OrderService { public constructor( diff --git a/apps/api/src/app/core/current-rate.service.spec.ts b/apps/api/src/app/portfolio/current-rate.service.spec.ts similarity index 96% rename from apps/api/src/app/core/current-rate.service.spec.ts rename to apps/api/src/app/portfolio/current-rate.service.spec.ts index 271be25b9..5df9fc1c9 100644 --- a/apps/api/src/app/core/current-rate.service.spec.ts +++ b/apps/api/src/app/portfolio/current-rate.service.spec.ts @@ -1,8 +1,8 @@ -import { CurrentRateService } from '@ghostfolio/api/app/core/current-rate.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; +import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { Currency, MarketData } from '@prisma/client'; +import { CurrentRateService } from './current-rate.service'; import { MarketDataService } from './market-data.service'; jest.mock('./market-data.service', () => { diff --git a/apps/api/src/app/core/current-rate.service.ts b/apps/api/src/app/portfolio/current-rate.service.ts similarity index 91% rename from apps/api/src/app/core/current-rate.service.ts rename to apps/api/src/app/portfolio/current-rate.service.ts index 7cab79808..09c62a656 100644 --- a/apps/api/src/app/core/current-rate.service.ts +++ b/apps/api/src/app/portfolio/current-rate.service.ts @@ -1,13 +1,13 @@ -import { GetValueObject } from '@ghostfolio/api/app/core/interfaces/get-value-object.interface'; -import { GetValueParams } from '@ghostfolio/api/app/core/interfaces/get-value-params.interface'; -import { GetValuesParams } from '@ghostfolio/api/app/core/interfaces/get-values-params.interface'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; +import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { resetHours } from '@ghostfolio/common/helper'; import { Injectable } from '@nestjs/common'; import { isBefore, isToday } from 'date-fns'; import { flatten } from 'lodash'; +import { GetValueObject } from './interfaces/get-value-object.interface'; +import { GetValueParams } from './interfaces/get-value-params.interface'; +import { GetValuesParams } from './interfaces/get-values-params.interface'; import { MarketDataService } from './market-data.service'; @Injectable() diff --git a/apps/api/src/app/core/interfaces/current-positions.interface.ts b/apps/api/src/app/portfolio/interfaces/current-positions.interface.ts similarity index 100% rename from apps/api/src/app/core/interfaces/current-positions.interface.ts rename to apps/api/src/app/portfolio/interfaces/current-positions.interface.ts diff --git a/apps/api/src/app/core/interfaces/date-query.interface.ts b/apps/api/src/app/portfolio/interfaces/date-query.interface.ts similarity index 100% rename from apps/api/src/app/core/interfaces/date-query.interface.ts rename to apps/api/src/app/portfolio/interfaces/date-query.interface.ts diff --git a/apps/api/src/app/core/interfaces/get-value-object.interface.ts b/apps/api/src/app/portfolio/interfaces/get-value-object.interface.ts similarity index 100% rename from apps/api/src/app/core/interfaces/get-value-object.interface.ts rename to apps/api/src/app/portfolio/interfaces/get-value-object.interface.ts diff --git a/apps/api/src/app/core/interfaces/get-value-params.interface.ts b/apps/api/src/app/portfolio/interfaces/get-value-params.interface.ts similarity index 100% rename from apps/api/src/app/core/interfaces/get-value-params.interface.ts rename to apps/api/src/app/portfolio/interfaces/get-value-params.interface.ts diff --git a/apps/api/src/app/core/interfaces/get-values-params.interface.ts b/apps/api/src/app/portfolio/interfaces/get-values-params.interface.ts similarity index 69% rename from apps/api/src/app/core/interfaces/get-values-params.interface.ts rename to apps/api/src/app/portfolio/interfaces/get-values-params.interface.ts index 9f1338000..df5261bcc 100644 --- a/apps/api/src/app/core/interfaces/get-values-params.interface.ts +++ b/apps/api/src/app/portfolio/interfaces/get-values-params.interface.ts @@ -1,6 +1,7 @@ -import { DateQuery } from '@ghostfolio/api/app/core/interfaces/date-query.interface'; import { Currency } from '@prisma/client'; +import { DateQuery } from './date-query.interface'; + export interface GetValuesParams { currencies: { [symbol: string]: Currency }; dateQuery: DateQuery; diff --git a/apps/api/src/app/core/interfaces/portfolio-order.interface.ts b/apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts similarity index 100% rename from apps/api/src/app/core/interfaces/portfolio-order.interface.ts rename to apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts diff --git a/apps/api/src/app/core/interfaces/timeline-period.interface.ts b/apps/api/src/app/portfolio/interfaces/timeline-period.interface.ts similarity index 100% rename from apps/api/src/app/core/interfaces/timeline-period.interface.ts rename to apps/api/src/app/portfolio/interfaces/timeline-period.interface.ts diff --git a/apps/api/src/app/core/interfaces/timeline-specification.interface.ts b/apps/api/src/app/portfolio/interfaces/timeline-specification.interface.ts similarity index 100% rename from apps/api/src/app/core/interfaces/timeline-specification.interface.ts rename to apps/api/src/app/portfolio/interfaces/timeline-specification.interface.ts diff --git a/apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts b/apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts similarity index 100% rename from apps/api/src/app/core/interfaces/transaction-point-symbol.interface.ts rename to apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts diff --git a/apps/api/src/app/portfolio/interfaces/transaction-point.interface.ts b/apps/api/src/app/portfolio/interfaces/transaction-point.interface.ts new file mode 100644 index 000000000..178df3456 --- /dev/null +++ b/apps/api/src/app/portfolio/interfaces/transaction-point.interface.ts @@ -0,0 +1,6 @@ +import { TransactionPointSymbol } from './transaction-point-symbol.interface'; + +export interface TransactionPoint { + date: string; + items: TransactionPointSymbol[]; +} diff --git a/apps/api/src/app/core/market-data.service.ts b/apps/api/src/app/portfolio/market-data.service.ts similarity index 100% rename from apps/api/src/app/core/market-data.service.ts rename to apps/api/src/app/portfolio/market-data.service.ts diff --git a/apps/api/src/app/core/portfolio-calculator.spec.ts b/apps/api/src/app/portfolio/portfolio-calculator.spec.ts similarity index 98% rename from apps/api/src/app/core/portfolio-calculator.spec.ts rename to apps/api/src/app/portfolio/portfolio-calculator.spec.ts index e71c0b3ef..9bf57bb27 100644 --- a/apps/api/src/app/core/portfolio-calculator.spec.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.spec.ts @@ -1,11 +1,3 @@ -import { CurrentRateService } from '@ghostfolio/api/app/core/current-rate.service'; -import { GetValueParams } from '@ghostfolio/api/app/core/interfaces/get-value-params.interface'; -import { GetValuesParams } from '@ghostfolio/api/app/core/interfaces/get-values-params.interface'; -import { PortfolioOrder } from '@ghostfolio/api/app/core/interfaces/portfolio-order.interface'; -import { TimelinePeriod } from '@ghostfolio/api/app/core/interfaces/timeline-period.interface'; -import { TimelineSpecification } from '@ghostfolio/api/app/core/interfaces/timeline-specification.interface'; -import { TransactionPoint } from '@ghostfolio/api/app/core/interfaces/transaction-point.interface'; -import { PortfolioCalculator } from '@ghostfolio/api/app/core/portfolio-calculator'; import { OrderType } from '@ghostfolio/api/models/order-type'; import { parseDate, resetHours } from '@ghostfolio/common/helper'; import { Currency } from '@prisma/client'; @@ -18,6 +10,15 @@ import { isSameDay } from 'date-fns'; +import { CurrentRateService } from './current-rate.service'; +import { GetValueParams } from './interfaces/get-value-params.interface'; +import { GetValuesParams } from './interfaces/get-values-params.interface'; +import { PortfolioOrder } from './interfaces/portfolio-order.interface'; +import { TimelinePeriod } from './interfaces/timeline-period.interface'; +import { TimelineSpecification } from './interfaces/timeline-specification.interface'; +import { TransactionPoint } from './interfaces/transaction-point.interface'; +import { PortfolioCalculator } from './portfolio-calculator'; + function mockGetValue(symbol: string, date: Date) { switch (symbol) { case 'AMZN': @@ -67,7 +68,7 @@ function mockGetValue(symbol: string, date: Date) { } } -jest.mock('@ghostfolio/api/app/core/current-rate.service', () => { +jest.mock('./current-rate.service', () => { return { // eslint-disable-next-line @typescript-eslint/naming-convention CurrentRateService: jest.fn().mockImplementation(() => { diff --git a/apps/api/src/app/core/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts similarity index 95% rename from apps/api/src/app/core/portfolio-calculator.ts rename to apps/api/src/app/portfolio/portfolio-calculator.ts index 91c9a8123..ba78426d6 100644 --- a/apps/api/src/app/core/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -1,14 +1,3 @@ -import { CurrentRateService } from '@ghostfolio/api/app/core/current-rate.service'; -import { CurrentPositions } from '@ghostfolio/api/app/core/interfaces/current-positions.interface'; -import { GetValueObject } from '@ghostfolio/api/app/core/interfaces/get-value-object.interface'; -import { PortfolioOrder } from '@ghostfolio/api/app/core/interfaces/portfolio-order.interface'; -import { TimelinePeriod } from '@ghostfolio/api/app/core/interfaces/timeline-period.interface'; -import { - Accuracy, - TimelineSpecification -} from '@ghostfolio/api/app/core/interfaces/timeline-specification.interface'; -import { TransactionPointSymbol } from '@ghostfolio/api/app/core/interfaces/transaction-point-symbol.interface'; -import { TransactionPoint } from '@ghostfolio/api/app/core/interfaces/transaction-point.interface'; import { OrderType } from '@ghostfolio/api/models/order-type'; import { DATE_FORMAT, parseDate, resetHours } from '@ghostfolio/common/helper'; import { TimelinePosition } from '@ghostfolio/common/interfaces'; @@ -27,6 +16,18 @@ import { } from 'date-fns'; import { flatten } from 'lodash'; +import { CurrentRateService } from './current-rate.service'; +import { CurrentPositions } from './interfaces/current-positions.interface'; +import { GetValueObject } from './interfaces/get-value-object.interface'; +import { PortfolioOrder } from './interfaces/portfolio-order.interface'; +import { TimelinePeriod } from './interfaces/timeline-period.interface'; +import { + Accuracy, + TimelineSpecification +} from './interfaces/timeline-specification.interface'; +import { TransactionPointSymbol } from './interfaces/transaction-point-symbol.interface'; +import { TransactionPoint } from './interfaces/transaction-point.interface'; + export class PortfolioCalculator { private transactionPoints: TransactionPoint[]; diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index 96a2e2b55..58d6edd47 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -46,7 +46,7 @@ export class PortfolioController { public constructor( private readonly exchangeRateDataService: ExchangeRateDataService, private readonly impersonationService: ImpersonationService, - private portfolioService: PortfolioService, + private readonly portfolioService: PortfolioService, @Inject(REQUEST) private readonly request: RequestWithUser ) {} diff --git a/apps/api/src/app/portfolio/portfolio.module.ts b/apps/api/src/app/portfolio/portfolio.module.ts index 3a4aa29e1..e3fb146ed 100644 --- a/apps/api/src/app/portfolio/portfolio.module.ts +++ b/apps/api/src/app/portfolio/portfolio.module.ts @@ -1,50 +1,40 @@ import { AccountService } from '@ghostfolio/api/app/account/account.service'; -import { CacheService } from '@ghostfolio/api/app/cache/cache.service'; -import { CurrentRateService } from '@ghostfolio/api/app/core/current-rate.service'; -import { MarketDataService } from '@ghostfolio/api/app/core/market-data.service'; -import { OrderService } from '@ghostfolio/api/app/order/order.service'; -import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; +import { OrderModule } from '@ghostfolio/api/app/order/order.module'; import { UserService } from '@ghostfolio/api/app/user/user.service'; -import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; -import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; -import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; -import { ImpersonationService } from '@ghostfolio/api/services/impersonation.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; -import { RulesService } from '@ghostfolio/api/services/rules.service'; +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering.module'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { ExchangeRateDataModule } from '@ghostfolio/api/services/exchange-rate-data.module'; +import { ImpersonationModule } from '@ghostfolio/api/services/impersonation.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service'; import { Module } from '@nestjs/common'; +import { CurrentRateService } from './current-rate.service'; +import { MarketDataService } from './market-data.service'; import { PortfolioController } from './portfolio.controller'; import { PortfolioService } from './portfolio.service'; +import { RulesService } from './rules.service'; @Module({ - imports: [RedisCacheModule], + imports: [ + ConfigurationModule, + DataGatheringModule, + DataProviderModule, + ExchangeRateDataModule, + ImpersonationModule, + OrderModule, + PrismaModule + ], controllers: [PortfolioController], providers: [ AccountService, - AlphaVantageService, - CacheService, CurrentRateService, - ConfigurationService, - DataGatheringService, - DataProviderService, - ExchangeRateDataService, - GhostfolioScraperApiService, - ImpersonationService, MarketDataService, - OrderService, PortfolioService, - PrismaService, - RakutenRapidApiService, RulesService, SymbolProfileService, - UserService, - YahooFinanceService + UserService ] }) export class PortfolioModule {} diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index ccb287e27..8e5e50aec 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1,11 +1,11 @@ import { AccountService } from '@ghostfolio/api/app/account/account.service'; import { CashDetails } from '@ghostfolio/api/app/account/interfaces/cash-details.interface'; -import { CurrentRateService } from '@ghostfolio/api/app/core/current-rate.service'; -import { PortfolioOrder } from '@ghostfolio/api/app/core/interfaces/portfolio-order.interface'; -import { TimelineSpecification } from '@ghostfolio/api/app/core/interfaces/timeline-specification.interface'; -import { TransactionPoint } from '@ghostfolio/api/app/core/interfaces/transaction-point.interface'; -import { PortfolioCalculator } from '@ghostfolio/api/app/core/portfolio-calculator'; import { OrderService } from '@ghostfolio/api/app/order/order.service'; +import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { PortfolioOrder } from '@ghostfolio/api/app/portfolio/interfaces/portfolio-order.interface'; +import { TimelineSpecification } from '@ghostfolio/api/app/portfolio/interfaces/timeline-specification.interface'; +import { TransactionPoint } from '@ghostfolio/api/app/portfolio/interfaces/transaction-point.interface'; +import { PortfolioCalculator } from '@ghostfolio/api/app/portfolio/portfolio-calculator'; import { OrderType } from '@ghostfolio/api/models/order-type'; import { AccountClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/current-investment'; import { AccountClusterRiskInitialInvestment } from '@ghostfolio/api/models/rules/account-cluster-risk/initial-investment'; @@ -15,12 +15,11 @@ import { CurrencyClusterRiskBaseCurrencyInitialInvestment } from '@ghostfolio/ap import { CurrencyClusterRiskCurrentInvestment } from '@ghostfolio/api/models/rules/currency-cluster-risk/current-investment'; import { CurrencyClusterRiskInitialInvestment } from '@ghostfolio/api/models/rules/currency-cluster-risk/initial-investment'; import { FeeRatioInitialInvestment } from '@ghostfolio/api/models/rules/fees/fee-ratio-initial-investment'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; +import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { ImpersonationService } from '@ghostfolio/api/services/impersonation.service'; import { MarketState } from '@ghostfolio/api/services/interfaces/interfaces'; import { EnhancedSymbolProfile } from '@ghostfolio/api/services/interfaces/symbol-profile.interface'; -import { RulesService } from '@ghostfolio/api/services/rules.service'; import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile.service'; import { UNKNOWN_KEY, ghostfolioCashSymbol } from '@ghostfolio/common/config'; import { DATE_FORMAT, parseDate } from '@ghostfolio/common/helper'; @@ -65,6 +64,7 @@ import { HistoricalDataItem, PortfolioPositionDetail } from './interfaces/portfolio-position-detail.interface'; +import { RulesService } from './rules.service'; @Injectable() export class PortfolioService { diff --git a/apps/api/src/services/rules.service.ts b/apps/api/src/app/portfolio/rules.service.ts similarity index 92% rename from apps/api/src/services/rules.service.ts rename to apps/api/src/app/portfolio/rules.service.ts index d9e6183d0..63f70771c 100644 --- a/apps/api/src/services/rules.service.ts +++ b/apps/api/src/app/portfolio/rules.service.ts @@ -1,9 +1,8 @@ import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; +import { Rule } from '@ghostfolio/api/models/rule'; import { Injectable } from '@nestjs/common'; import { Currency } from '@prisma/client'; -import { Rule } from '../models/rule'; - @Injectable() export class RulesService { public constructor() {} diff --git a/apps/api/src/app/symbol/symbol.module.ts b/apps/api/src/app/symbol/symbol.module.ts index 2fb3a9d76..7b0da89a2 100644 --- a/apps/api/src/app/symbol/symbol.module.ts +++ b/apps/api/src/app/symbol/symbol.module.ts @@ -1,27 +1,14 @@ -import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; -import { AlphaVantageService } from '@ghostfolio/api/services/data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; -import { PrismaService } from '@ghostfolio/api/services/prisma.service'; +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; import { Module } from '@nestjs/common'; import { SymbolController } from './symbol.controller'; import { SymbolService } from './symbol.service'; @Module({ - imports: [], + imports: [ConfigurationModule, DataProviderModule, PrismaModule], controllers: [SymbolController], - providers: [ - AlphaVantageService, - ConfigurationService, - DataProviderService, - GhostfolioScraperApiService, - PrismaService, - RakutenRapidApiService, - SymbolService, - YahooFinanceService - ] + providers: [SymbolService] }) export class SymbolModule {} diff --git a/apps/api/src/app/symbol/symbol.service.ts b/apps/api/src/app/symbol/symbol.service.ts index 0db0ba066..7fcafc4cc 100644 --- a/apps/api/src/app/symbol/symbol.service.ts +++ b/apps/api/src/app/symbol/symbol.service.ts @@ -1,4 +1,4 @@ -import { DataProviderService } from '@ghostfolio/api/services/data-provider.service'; +import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { Injectable } from '@nestjs/common'; import { Currency, DataSource } from '@prisma/client'; diff --git a/apps/api/src/models/rule.ts b/apps/api/src/models/rule.ts index 00a8cf65d..f725959fa 100644 --- a/apps/api/src/models/rule.ts +++ b/apps/api/src/models/rule.ts @@ -1,10 +1,10 @@ import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { UserSettings } from '@ghostfolio/api/models/interfaces/user-settings.interface'; +import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { groupBy } from '@ghostfolio/common/helper'; import { TimelinePosition } from '@ghostfolio/common/interfaces'; import { Currency } from '@prisma/client'; -import { ExchangeRateDataService } from '../services/exchange-rate-data.service'; import { EvaluationResult } from './interfaces/evaluation-result.interface'; import { RuleInterface } from './interfaces/rule.interface'; diff --git a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts index 4c5fe01da..06e24960d 100644 --- a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts +++ b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts @@ -1,4 +1,4 @@ -import { CurrentPositions } from '@ghostfolio/api/app/core/interfaces/current-positions.interface'; +import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface'; import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { UserSettings } from '@ghostfolio/api/models/interfaces/user-settings.interface'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; diff --git a/apps/api/src/models/rules/currency-cluster-risk/base-currency-initial-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/base-currency-initial-investment.ts index 02ea09770..548137e04 100644 --- a/apps/api/src/models/rules/currency-cluster-risk/base-currency-initial-investment.ts +++ b/apps/api/src/models/rules/currency-cluster-risk/base-currency-initial-investment.ts @@ -1,4 +1,4 @@ -import { CurrentPositions } from '@ghostfolio/api/app/core/interfaces/current-positions.interface'; +import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface'; import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { UserSettings } from '@ghostfolio/api/models/interfaces/user-settings.interface'; import { Currency } from '@prisma/client'; diff --git a/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts index 12a6c22b6..eb6be3a2f 100644 --- a/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts +++ b/apps/api/src/models/rules/currency-cluster-risk/current-investment.ts @@ -1,4 +1,4 @@ -import { CurrentPositions } from '@ghostfolio/api/app/core/interfaces/current-positions.interface'; +import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface'; import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { UserSettings } from '@ghostfolio/api/models/interfaces/user-settings.interface'; import { Currency } from '@prisma/client'; diff --git a/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts index 3ce70a1e6..993e39247 100644 --- a/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts +++ b/apps/api/src/models/rules/currency-cluster-risk/initial-investment.ts @@ -1,4 +1,4 @@ -import { CurrentPositions } from '@ghostfolio/api/app/core/interfaces/current-positions.interface'; +import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface'; import { RuleSettings } from '@ghostfolio/api/models/interfaces/rule-settings.interface'; import { UserSettings } from '@ghostfolio/api/models/interfaces/user-settings.interface'; import { Currency } from '@prisma/client'; diff --git a/apps/api/src/services/configuration.module.ts b/apps/api/src/services/configuration.module.ts new file mode 100644 index 000000000..b91475941 --- /dev/null +++ b/apps/api/src/services/configuration.module.ts @@ -0,0 +1,8 @@ +import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; +import { Module } from '@nestjs/common'; + +@Module({ + providers: [ConfigurationService], + exports: [ConfigurationService] +}) +export class ConfigurationModule {} diff --git a/apps/api/src/services/data-gathering.module.ts b/apps/api/src/services/data-gathering.module.ts new file mode 100644 index 000000000..539c76ac3 --- /dev/null +++ b/apps/api/src/services/data-gathering.module.ts @@ -0,0 +1,12 @@ +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; +import { Module } from '@nestjs/common'; + +@Module({ + imports: [ConfigurationModule, DataProviderModule, PrismaModule], + providers: [DataGatheringService], + exports: [DataGatheringService] +}) +export class DataGatheringModule {} diff --git a/apps/api/src/services/data-gathering.service.ts b/apps/api/src/services/data-gathering.service.ts index f853e5dbc..eff9d3c21 100644 --- a/apps/api/src/services/data-gathering.service.ts +++ b/apps/api/src/services/data-gathering.service.ts @@ -19,7 +19,7 @@ import { } from 'date-fns'; import { ConfigurationService } from './configuration.service'; -import { DataProviderService } from './data-provider.service'; +import { DataProviderService } from './data-provider/data-provider.service'; import { GhostfolioScraperApiService } from './data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; import { IDataGatheringItem } from './interfaces/interfaces'; import { PrismaService } from './prisma.service'; diff --git a/apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts b/apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts index 9bfc861a4..6bf88feec 100644 --- a/apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts +++ b/apps/api/src/services/data-provider/alpha-vantage/alpha-vantage.service.ts @@ -1,11 +1,11 @@ import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface'; +import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { Granularity } from '@ghostfolio/common/types'; import { Injectable } from '@nestjs/common'; import { DataSource } from '@prisma/client'; import { isAfter, isBefore, parse } from 'date-fns'; -import { ConfigurationService } from '../../configuration.service'; import { DataProviderInterface } from '../../interfaces/data-provider.interface'; import { IDataProviderHistoricalResponse, diff --git a/apps/api/src/services/data-provider/data-provider.module.ts b/apps/api/src/services/data-provider/data-provider.module.ts new file mode 100644 index 000000000..5c677751d --- /dev/null +++ b/apps/api/src/services/data-provider/data-provider.module.ts @@ -0,0 +1,22 @@ +import { ConfigurationModule } from '@ghostfolio/api/services/configuration.module'; +import { GhostfolioScraperApiService } from '@ghostfolio/api/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; +import { RakutenRapidApiService } from '@ghostfolio/api/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; +import { YahooFinanceService } from '@ghostfolio/api/services/data-provider/yahoo-finance/yahoo-finance.service'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; +import { Module } from '@nestjs/common'; + +import { AlphaVantageService } from './alpha-vantage/alpha-vantage.service'; +import { DataProviderService } from './data-provider.service'; + +@Module({ + imports: [ConfigurationModule, PrismaModule], + providers: [ + AlphaVantageService, + DataProviderService, + GhostfolioScraperApiService, + RakutenRapidApiService, + YahooFinanceService + ], + exports: [DataProviderService, GhostfolioScraperApiService] +}) +export class DataProviderModule {} diff --git a/apps/api/src/services/data-provider.service.ts b/apps/api/src/services/data-provider/data-provider.service.ts similarity index 91% rename from apps/api/src/services/data-provider.service.ts rename to apps/api/src/services/data-provider/data-provider.service.ts index 64f82bd40..81c8982cc 100644 --- a/apps/api/src/services/data-provider.service.ts +++ b/apps/api/src/services/data-provider/data-provider.service.ts @@ -1,4 +1,11 @@ import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface'; +import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; +import { + IDataGatheringItem, + IDataProviderHistoricalResponse, + IDataProviderResponse +} from '@ghostfolio/api/services/interfaces/interfaces'; +import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { DATE_FORMAT, isGhostfolioScraperApiSymbol, @@ -9,17 +16,10 @@ import { Injectable } from '@nestjs/common'; import { DataSource, MarketData } from '@prisma/client'; import { format } from 'date-fns'; -import { ConfigurationService } from './configuration.service'; -import { AlphaVantageService } from './data-provider/alpha-vantage/alpha-vantage.service'; -import { GhostfolioScraperApiService } from './data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service'; -import { RakutenRapidApiService } from './data-provider/rakuten-rapid-api/rakuten-rapid-api.service'; -import { YahooFinanceService } from './data-provider/yahoo-finance/yahoo-finance.service'; -import { - IDataGatheringItem, - IDataProviderHistoricalResponse, - IDataProviderResponse -} from './interfaces/interfaces'; -import { PrismaService } from './prisma.service'; +import { AlphaVantageService } from './alpha-vantage/alpha-vantage.service'; +import { GhostfolioScraperApiService } from './ghostfolio-scraper-api/ghostfolio-scraper-api.service'; +import { RakutenRapidApiService } from './rakuten-rapid-api/rakuten-rapid-api.service'; +import { YahooFinanceService } from './yahoo-finance/yahoo-finance.service'; @Injectable() export class DataProviderService { diff --git a/apps/api/src/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service.ts b/apps/api/src/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service.ts index 7b41cd12e..805a4edcb 100644 --- a/apps/api/src/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service.ts +++ b/apps/api/src/services/data-provider/ghostfolio-scraper-api/ghostfolio-scraper-api.service.ts @@ -1,4 +1,5 @@ import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface'; +import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { DATE_FORMAT, getYesterday, @@ -18,7 +19,6 @@ import { IDataProviderResponse, MarketState } from '../../interfaces/interfaces'; -import { PrismaService } from '../../prisma.service'; import { ScraperConfig } from './interfaces/scraper-config.interface'; @Injectable() diff --git a/apps/api/src/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service.ts b/apps/api/src/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service.ts index ee9f29ce7..3b07301ab 100644 --- a/apps/api/src/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service.ts +++ b/apps/api/src/services/data-provider/rakuten-rapid-api/rakuten-rapid-api.service.ts @@ -1,4 +1,6 @@ import { LookupItem } from '@ghostfolio/api/app/symbol/interfaces/lookup-item.interface'; +import { ConfigurationService } from '@ghostfolio/api/services/configuration.service'; +import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { DATE_FORMAT, getToday, @@ -11,14 +13,12 @@ import { DataSource } from '@prisma/client'; import * as bent from 'bent'; import { format, subMonths, subWeeks, subYears } from 'date-fns'; -import { ConfigurationService } from '../../configuration.service'; import { DataProviderInterface } from '../../interfaces/data-provider.interface'; import { IDataProviderHistoricalResponse, IDataProviderResponse, MarketState } from '../../interfaces/interfaces'; -import { PrismaService } from '../../prisma.service'; @Injectable() export class RakutenRapidApiService implements DataProviderInterface { diff --git a/apps/api/src/services/exchange-rate-data.module.ts b/apps/api/src/services/exchange-rate-data.module.ts new file mode 100644 index 000000000..c95eb1ac1 --- /dev/null +++ b/apps/api/src/services/exchange-rate-data.module.ts @@ -0,0 +1,10 @@ +import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; +import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; +import { Module } from '@nestjs/common'; + +@Module({ + imports: [DataProviderModule], + providers: [ExchangeRateDataService], + exports: [ExchangeRateDataService] +}) +export class ExchangeRateDataModule {} diff --git a/apps/api/src/services/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data.service.ts index cc3fc4cb1..afb6ea122 100644 --- a/apps/api/src/services/exchange-rate-data.service.ts +++ b/apps/api/src/services/exchange-rate-data.service.ts @@ -5,7 +5,7 @@ import { Currency } from '@prisma/client'; import { format } from 'date-fns'; import { isNumber } from 'lodash'; -import { DataProviderService } from './data-provider.service'; +import { DataProviderService } from './data-provider/data-provider.service'; @Injectable() export class ExchangeRateDataService { diff --git a/apps/api/src/services/impersonation.module.ts b/apps/api/src/services/impersonation.module.ts new file mode 100644 index 000000000..00be6e68f --- /dev/null +++ b/apps/api/src/services/impersonation.module.ts @@ -0,0 +1,10 @@ +import { ImpersonationService } from '@ghostfolio/api/services/impersonation.service'; +import { PrismaModule } from '@ghostfolio/api/services/prisma.module'; +import { Module } from '@nestjs/common'; + +@Module({ + imports: [PrismaModule], + providers: [ImpersonationService], + exports: [ImpersonationService] +}) +export class ImpersonationModule {} diff --git a/apps/api/src/services/prisma.module.ts b/apps/api/src/services/prisma.module.ts new file mode 100644 index 000000000..ee8c8b8c5 --- /dev/null +++ b/apps/api/src/services/prisma.module.ts @@ -0,0 +1,8 @@ +import { PrismaService } from '@ghostfolio/api/services/prisma.service'; +import { Module } from '@nestjs/common'; + +@Module({ + providers: [PrismaService], + exports: [PrismaService] +}) +export class PrismaModule {}