Browse Source

Fix creation of asset profiles with symbol in wrong letter case by using original symbol

pull/7727/head
Thomas Kaul 3 days ago
parent
commit
a6124891e7
  1. 22
      apps/api/src/app/activities/activities.controller.ts
  2. 22
      apps/api/src/app/endpoints/watchlist/watchlist.service.ts
  3. 4
      apps/api/src/services/data-provider/data-provider.service.ts
  4. 10
      apps/api/src/services/queues/data-gathering/data-gathering.service.ts

22
apps/api/src/app/activities/activities.controller.ts

@ -12,6 +12,7 @@ import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper'
import { DATA_GATHERING_QUEUE_PRIORITY_HIGH } from '@ghostfolio/common/config'; import { DATA_GATHERING_QUEUE_PRIORITY_HIGH } from '@ghostfolio/common/config';
import { CreateOrderDto, UpdateOrderDto } from '@ghostfolio/common/dtos'; import { CreateOrderDto, UpdateOrderDto } from '@ghostfolio/common/dtos';
import { SubscriptionType } from '@ghostfolio/common/enums'; import { SubscriptionType } from '@ghostfolio/common/enums';
import { getAssetProfileIdentifier } from '@ghostfolio/common/helper';
import { import {
ActivitiesResponse, ActivitiesResponse,
ActivityResponse ActivityResponse
@ -32,7 +33,7 @@ import {
Query, Query,
UseInterceptors UseInterceptors
} from '@nestjs/common'; } from '@nestjs/common';
import { Order } from '@prisma/client'; import { Order, SymbolProfile } from '@prisma/client';
import { parseISO } from 'date-fns'; import { parseISO } from 'date-fns';
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; import { StatusCodes, getReasonPhrase } from 'http-status-codes';
@ -224,8 +225,12 @@ export class ActivitiesController {
? userSubscription ? userSubscription
: authenticatedUserSubscription; : authenticatedUserSubscription;
let assetProfiles: {
[assetProfileIdentifier: string]: Partial<SymbolProfile>;
};
try { try {
await this.dataProviderService.validateActivities({ assetProfiles = await this.dataProviderService.validateActivities({
subscription, subscription,
activitiesDto: [ activitiesDto: [
{ {
@ -251,6 +256,11 @@ export class ActivitiesController {
const customCurrency = data.customCurrency; const customCurrency = data.customCurrency;
const dataSource = data.dataSource; const dataSource = data.dataSource;
const symbol =
assetProfiles[
getAssetProfileIdentifier({ dataSource, symbol: data.symbol })
]?.symbol ?? data.symbol;
if (customCurrency) { if (customCurrency) {
data.currency = customCurrency; data.currency = customCurrency;
@ -268,12 +278,12 @@ export class ActivitiesController {
create: { create: {
currency, currency,
dataSource, dataSource,
symbol: data.symbol symbol
}, },
where: { where: {
dataSource_symbol: { dataSource_symbol: {
dataSource, dataSource,
symbol: data.symbol symbol
} }
} }
} }
@ -291,8 +301,8 @@ export class ActivitiesController {
dataGatheringItems: [ dataGatheringItems: [
{ {
dataSource, dataSource,
date: activity.date, symbol,
symbol: data.symbol date: activity.date
} }
], ],
priority: DATA_GATHERING_QUEUE_PRIORITY_HIGH priority: DATA_GATHERING_QUEUE_PRIORITY_HIGH

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

@ -26,10 +26,12 @@ export class WatchlistService {
public async createWatchlistItem({ public async createWatchlistItem({
dataSource, dataSource,
symbol, symbol: aSymbol,
userId userId
}: { userId: string } & AssetProfileIdentifier): Promise<void> { }: { userId: string } & AssetProfileIdentifier): Promise<void> {
const symbolProfile = await this.prismaService.symbolProfile.findUnique({ let symbol = aSymbol;
let symbolProfile = await this.prismaService.symbolProfile.findUnique({
where: { where: {
dataSource_symbol: { dataSource, symbol } dataSource_symbol: { dataSource, symbol }
} }
@ -49,9 +51,19 @@ export class WatchlistService {
); );
} }
await this.symbolProfileService.add( symbol = assetProfile.symbol;
assetProfile as Prisma.SymbolProfileCreateInput
); symbolProfile = await this.prismaService.symbolProfile.findUnique({
where: {
dataSource_symbol: { dataSource, symbol }
}
});
if (!symbolProfile) {
await this.symbolProfileService.add(
assetProfile as Prisma.SymbolProfileCreateInput
);
}
} }
await this.dataGatheringService.gatherSymbol({ await this.dataGatheringService.gatherSymbol({

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

@ -130,8 +130,8 @@ export class DataProviderService implements OnModuleInit {
}) })
] = { ] = {
...assetProfile, ...assetProfile,
symbol, name: formatAssetProfileName(assetProfile),
name: formatAssetProfileName(assetProfile) symbol: assetProfile.symbol ?? symbol
}; };
} }
}) })

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

@ -95,8 +95,13 @@ export class DataGatheringService {
assetProfileIdentifiers assetProfileIdentifiers
); );
for (const assetProfile of Object.values(assetProfiles)) { for (const { dataSource, symbol } of assetProfileIdentifiers) {
const { symbol } = assetProfile; const assetProfile =
assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })];
if (!assetProfile) {
continue;
}
const symbolProfile = symbolProfiles.find( const symbolProfile = symbolProfiles.find(
({ symbol: symbolProfileSymbol }) => { ({ symbol: symbolProfileSymbol }) => {
@ -137,7 +142,6 @@ export class DataGatheringService {
countries, countries,
currency, currency,
cusip, cusip,
dataSource,
figi, figi,
figiComposite, figiComposite,
figiShareClass, figiShareClass,

Loading…
Cancel
Save