Browse Source

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

pull/7727/head
Thomas Kaul 2 days ago
parent
commit
35ca9cf600
  1. 14
      apps/api/src/app/admin/admin.service.ts
  2. 11
      apps/api/src/app/import/import.service.ts
  3. 14
      apps/api/src/services/symbol-profile/symbol-profile.service.spec.ts
  4. 11
      apps/api/src/services/symbol-profile/symbol-profile.service.ts

14
apps/api/src/app/admin/admin.service.ts

@ -102,9 +102,17 @@ export class AdminService {
); );
} }
return this.symbolProfileService.add( const symbolOfAssetProfile =
assetProfile as Prisma.SymbolProfileCreateInput await this.symbolProfileService.getSymbolOfAssetProfile({
); dataSource,
symbol,
symbolOfDataProvider: assetProfile.symbol
});
return this.symbolProfileService.add({
...assetProfile,
symbol: symbolOfAssetProfile
} as Prisma.SymbolProfileCreateInput);
} catch (error) { } catch (error) {
if ( if (
error instanceof Prisma.PrismaClientKnownRequestError && error instanceof Prisma.PrismaClientKnownRequestError &&

11
apps/api/src/app/import/import.service.ts

@ -748,7 +748,16 @@ export class ImportService {
const assetProfile = const assetProfile =
assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })]; assetProfiles[getAssetProfileIdentifier({ dataSource, symbol })];
if (assetProfile) { const assetProfileInImport = assetProfilesWithMarketDataDto?.some(
(assetProfileWithMarketData) => {
return (
assetProfileWithMarketData.dataSource === dataSource &&
assetProfileWithMarketData.symbol === symbol
);
}
);
if (assetProfile && !assetProfileInImport) {
assetProfile.symbol = assetProfile.symbol =
await this.symbolProfileService.getSymbolOfAssetProfile({ await this.symbolProfileService.getSymbolOfAssetProfile({
dataSource, dataSource,

14
apps/api/src/services/symbol-profile/symbol-profile.service.spec.ts

@ -58,6 +58,20 @@ describe('SymbolProfileService', () => {
expect(symbol).toEqual('aapl'); expect(symbol).toEqual('aapl');
}); });
it('Ignores an asset profile which a wildcard of the query matched', async () => {
prismaService.symbolProfile.findMany.mockResolvedValue([
{ symbol: 'AAPL' }
]);
const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.YAHOO,
symbol: 'aa_l',
symbolOfDataProvider: 'AA_L'
});
expect(symbol).toEqual('AA_L');
});
it('Uses the symbol of the data provider if no asset profile exists', async () => { it('Uses the symbol of the data provider if no asset profile exists', async () => {
const symbol = await symbolProfileService.getSymbolOfAssetProfile({ const symbol = await symbolProfileService.getSymbolOfAssetProfile({
dataSource: DataSource.YAHOO, dataSource: DataSource.YAHOO,

11
apps/api/src/services/symbol-profile/symbol-profile.service.ts

@ -1,6 +1,9 @@
import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service';
import { UNKNOWN_KEY } from '@ghostfolio/common/config'; import { UNKNOWN_KEY } from '@ghostfolio/common/config';
import { applyAssetProfileOverrides } from '@ghostfolio/common/helper'; import {
applyAssetProfileOverrides,
isSameSymbol
} from '@ghostfolio/common/helper';
import { import {
AssetProfileIdentifier, AssetProfileIdentifier,
EnhancedAssetProfile, EnhancedAssetProfile,
@ -140,13 +143,17 @@ export class SymbolProfileService {
return symbol; return symbol;
} }
const symbolProfiles = await this.prismaService.symbolProfile.findMany({ const symbolProfiles = (
await this.prismaService.symbolProfile.findMany({
orderBy: { symbol: 'asc' }, orderBy: { symbol: 'asc' },
select: { symbol: true }, select: { symbol: true },
where: { where: {
dataSource, dataSource,
symbol: { equals: symbol, mode: 'insensitive' } symbol: { equals: symbol, mode: 'insensitive' }
} }
})
).filter(({ symbol: symbolOfSymbolProfile }) => {
return isSameSymbol({ symbol1: symbol, symbol2: symbolOfSymbolProfile });
}); });
const symbolProfile = const symbolProfile =

Loading…
Cancel
Save