Browse Source

Bugfix/fix create watchlist item for new asset profile (#4625)

* Fix create watchlist item for new asset profile
pull/4627/head
Thomas Kaul 1 day ago
committed by GitHub
parent
commit
d919622932
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      apps/api/src/app/endpoints/watchlist/watchlist.module.ts
  2. 31
      apps/api/src/app/endpoints/watchlist/watchlist.service.ts
  3. 2
      apps/client/src/app/pages/home/home-page.component.ts

6
apps/api/src/app/endpoints/watchlist/watchlist.module.ts

@ -1,6 +1,9 @@
import { TransformDataSourceInRequestModule } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.module'; import { TransformDataSourceInRequestModule } from '@ghostfolio/api/interceptors/transform-data-source-in-request/transform-data-source-in-request.module';
import { TransformDataSourceInResponseModule } from '@ghostfolio/api/interceptors/transform-data-source-in-response/transform-data-source-in-response.module'; import { TransformDataSourceInResponseModule } from '@ghostfolio/api/interceptors/transform-data-source-in-response/transform-data-source-in-response.module';
import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module';
import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module'; import { PrismaModule } from '@ghostfolio/api/services/prisma/prisma.module';
import { DataGatheringModule } from '@ghostfolio/api/services/queues/data-gathering/data-gathering.module';
import { SymbolProfileModule } from '@ghostfolio/api/services/symbol-profile/symbol-profile.module';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
@ -10,7 +13,10 @@ import { WatchlistService } from './watchlist.service';
@Module({ @Module({
controllers: [WatchlistController], controllers: [WatchlistController],
imports: [ imports: [
DataGatheringModule,
DataProviderModule,
PrismaModule, PrismaModule,
SymbolProfileModule,
TransformDataSourceInRequestModule, TransformDataSourceInRequestModule,
TransformDataSourceInResponseModule TransformDataSourceInResponseModule
], ],

31
apps/api/src/app/endpoints/watchlist/watchlist.service.ts

@ -1,12 +1,20 @@
import { DataProviderService } from '@ghostfolio/api/services/data-provider/data-provider.service';
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
import { DataGatheringService } from '@ghostfolio/api/services/queues/data-gathering/data-gathering.service';
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service';
import { AssetProfileIdentifier } from '@ghostfolio/common/interfaces'; import { AssetProfileIdentifier } from '@ghostfolio/common/interfaces';
import { Injectable, NotFoundException } from '@nestjs/common'; import { BadRequestException, Injectable } from '@nestjs/common';
import { DataSource } from '@prisma/client'; import { DataSource, Prisma } from '@prisma/client';
@Injectable() @Injectable()
export class WatchlistService { export class WatchlistService {
public constructor(private readonly prismaService: PrismaService) {} public constructor(
private readonly dataGatheringService: DataGatheringService,
private readonly dataProviderService: DataProviderService,
private readonly prismaService: PrismaService,
private readonly symbolProfileService: SymbolProfileService
) {}
public async createWatchlistItem({ public async createWatchlistItem({
dataSource, dataSource,
@ -24,11 +32,26 @@ export class WatchlistService {
}); });
if (!symbolProfile) { if (!symbolProfile) {
throw new NotFoundException( const assetProfiles = await this.dataProviderService.getAssetProfiles([
{ dataSource, symbol }
]);
if (!assetProfiles[symbol]?.currency) {
throw new BadRequestException(
`Asset profile not found for ${symbol} (${dataSource})` `Asset profile not found for ${symbol} (${dataSource})`
); );
} }
await this.symbolProfileService.add(
assetProfiles[symbol] as Prisma.SymbolProfileCreateInput
);
}
await this.dataGatheringService.gatherSymbol({
dataSource,
symbol
});
await this.prismaService.user.update({ await this.prismaService.user.update({
data: { data: {
watchlist: { watchlist: {

2
apps/client/src/app/pages/home/home-page.component.ts

@ -54,7 +54,7 @@ export class HomePageComponent implements OnDestroy, OnInit {
path: ['/home', 'market'] path: ['/home', 'market']
}, },
{ {
iconName: 'star-outline', iconName: 'bookmark-outline',
label: $localize`Watchlist`, label: $localize`Watchlist`,
path: ['/home', 'watchlist'], path: ['/home', 'watchlist'],
showCondition: this.user?.settings?.isExperimentalFeatures showCondition: this.user?.settings?.isExperimentalFeatures

Loading…
Cancel
Save