Browse Source

Reuse AssetProfileIdentifier

pull/7087/head
Thomas Kaul 4 weeks ago
parent
commit
0fa7610d8a
  1. 19
      apps/api/src/app/endpoints/watchlist/watchlist.service.ts
  2. 3
      apps/api/src/app/portfolio/portfolio.service.spec.ts
  3. 9
      apps/api/src/app/portfolio/portfolio.service.ts
  4. 8
      apps/api/src/events/asset-profile-changed.listener.ts
  5. 4
      apps/api/src/services/data-provider/data-provider.service.ts
  6. 8
      apps/api/src/services/queues/data-gathering/data-gathering.service.ts

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

@ -5,10 +5,13 @@ 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 { getAssetProfileIdentifier } from '@ghostfolio/common/helper';
import { WatchlistResponse } from '@ghostfolio/common/interfaces';
import {
AssetProfileIdentifier,
WatchlistResponse
} from '@ghostfolio/common/interfaces';
import { BadRequestException, Injectable } from '@nestjs/common';
import { DataSource, Prisma } from '@prisma/client';
import { Prisma } from '@prisma/client';
@Injectable()
export class WatchlistService {
@ -25,11 +28,7 @@ export class WatchlistService {
dataSource,
symbol,
userId
}: {
dataSource: DataSource;
symbol: string;
userId: string;
}): Promise<void> {
}: { userId: string } & AssetProfileIdentifier): Promise<void> {
const symbolProfile = await this.prismaService.symbolProfile.findUnique({
where: {
dataSource_symbol: { dataSource, symbol }
@ -73,11 +72,7 @@ export class WatchlistService {
dataSource,
symbol,
userId
}: {
dataSource: DataSource;
symbol: string;
userId: string;
}) {
}: { userId: string } & AssetProfileIdentifier) {
await this.prismaService.user.update({
data: {
watchlist: {

3
apps/api/src/app/portfolio/portfolio.service.spec.ts

@ -11,6 +11,7 @@ import { ImpersonationService } from '@ghostfolio/api/services/impersonation/imp
import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service';
import { UNKNOWN_KEY } from '@ghostfolio/common/config';
import { parseDate } from '@ghostfolio/common/helper';
import { AssetProfileIdentifier } from '@ghostfolio/common/interfaces';
import { Account, DataSource } from '@prisma/client';
import { Big } from 'big.js';
@ -198,7 +199,7 @@ describe('PortfolioService', () => {
portfolioService as unknown as {
getCashSymbolProfiles: (
aCashDetails: CashDetails
) => { dataSource: DataSource; symbol: string }[];
) => AssetProfileIdentifier[];
}
).getCashSymbolProfiles(cashDetails);

9
apps/api/src/app/portfolio/portfolio.service.ts

@ -46,6 +46,7 @@ import {
import {
AccountsResponse,
Activity,
AssetProfileIdentifier,
EnhancedSymbolProfile,
Filter,
HistoricalDataItem,
@ -776,11 +777,9 @@ export class PortfolioService {
symbol,
userId
}: {
dataSource: DataSource;
impersonationId: string;
symbol: string;
userId: string;
}): Promise<PortfolioHoldingResponse> {
} & AssetProfileIdentifier): Promise<PortfolioHoldingResponse> {
userId = await this.getUserId(impersonationId, userId);
const user = await this.userService.user({ id: userId });
const userCurrency = this.getUserCurrency(user);
@ -1381,12 +1380,10 @@ export class PortfolioService {
tags,
userId
}: {
dataSource: DataSource;
impersonationId: string;
symbol: string;
tags: Tag[];
userId: string;
}) {
} & AssetProfileIdentifier) {
userId = await this.getUserId(impersonationId, userId);
await this.activitiesService.assignTags({

8
apps/api/src/events/asset-profile-changed.listener.ts

@ -5,10 +5,10 @@ import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-
import { DataGatheringService } from '@ghostfolio/api/services/queues/data-gathering/data-gathering.service';
import { DEFAULT_CURRENCY } from '@ghostfolio/common/config';
import { getAssetProfileIdentifier } from '@ghostfolio/common/helper';
import { AssetProfileIdentifier } from '@ghostfolio/common/interfaces';
import { Injectable, Logger } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
import { DataSource } from '@prisma/client';
import ms from 'ms';
import { AssetProfileChangedEvent } from './asset-profile-changed.event';
@ -64,11 +64,7 @@ export class AssetProfileChangedListener {
currency,
dataSource,
symbol
}: {
currency: string;
dataSource: DataSource;
symbol: string;
}) {
}: { currency: string } & AssetProfileIdentifier) {
this.logger.log(`Asset profile of ${symbol} (${dataSource}) has changed`);
if (

4
apps/api/src/services/data-provider/data-provider.service.ts

@ -320,12 +320,10 @@ export class DataProviderService implements OnModuleInit {
symbol,
to
}: {
dataSource: DataSource;
from: Date;
granularity: Granularity;
symbol: string;
to: Date;
}) {
} & AssetProfileIdentifier) {
return this.getDataProvider(DataSource[dataSource]).getDividends({
from,
granularity,

8
apps/api/src/services/queues/data-gathering/data-gathering.service.ts

@ -28,7 +28,7 @@ import {
import { InjectQueue } from '@nestjs/bull';
import { Inject, Injectable, Logger } from '@nestjs/common';
import { DataSource, Prisma } from '@prisma/client';
import { Prisma } from '@prisma/client';
import { JobOptions, Queue } from 'bull';
import { format, min, subDays, subMilliseconds, subYears } from 'date-fns';
import { isEmpty } from 'lodash';
@ -122,11 +122,7 @@ export class DataGatheringService {
dataSource,
date,
symbol
}: {
dataSource: DataSource;
date: Date;
symbol: string;
}) {
}: { date: Date } & AssetProfileIdentifier) {
try {
const historicalData = await this.dataProviderService.getHistoricalRaw({
assetProfileIdentifiers: [{ dataSource, symbol }],

Loading…
Cancel
Save