Browse Source

Fix issue with overriden names

pull/3200/head
Thomas Kaul 1 year ago
parent
commit
aa4fc3f727
  1. 65
      apps/api/src/app/order/order.service.ts
  2. 13
      libs/common/src/lib/interfaces/enhanced-symbol-profile.interface.ts

65
apps/api/src/app/order/order.service.ts

@ -23,7 +23,7 @@ import {
} from '@prisma/client';
import { Big } from 'big.js';
import { endOfToday, isAfter } from 'date-fns';
import { groupBy } from 'lodash';
import { groupBy, uniqBy } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { Activities } from './interfaces/activities.interface';
@ -320,7 +320,49 @@ export class OrderService {
this.prismaService.order.count({ where })
]);
const uniqueAssets = uniqBy(
orders.map(({ SymbolProfile }) => {
return {
dataSource: SymbolProfile.dataSource,
symbol: SymbolProfile.symbol
};
}),
({ dataSource, symbol }) => {
return getAssetProfileIdentifier({
dataSource,
symbol
});
}
);
const assetProfiles =
await this.symbolProfileService.getSymbolProfiles(uniqueAssets);
const activities = orders.map((order) => {
const {
assetClass,
assetSubClass,
comment,
createdAt,
currency,
dataSource,
figi,
figiComposite,
figiShareClass,
id,
isin,
name,
symbol,
symbolMapping,
updatedAt,
url
} = assetProfiles.find(({ dataSource, symbol }) => {
return (
dataSource === order.SymbolProfile.dataSource &&
symbol === order.SymbolProfile.symbol
);
});
const value = new Big(order.quantity).mul(order.unitPrice).toNumber();
return {
@ -332,6 +374,27 @@ export class OrderService {
order.SymbolProfile.currency,
userCurrency
),
SymbolProfile: {
assetClass,
assetSubClass,
comment,
createdAt,
currency,
dataSource,
figi,
figiComposite,
figiShareClass,
id,
isin,
name,
symbol,
symbolMapping,
updatedAt,
url,
countries: null,
scraperConfiguration: null,
sectors: null
},
// TODO: Use exchange rate of date
valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
value,

13
libs/common/src/lib/interfaces/enhanced-symbol-profile.interface.ts

@ -8,16 +8,19 @@ export interface EnhancedSymbolProfile {
activitiesCount: number;
assetClass: AssetClass;
assetSubClass: AssetSubClass;
comment: string | null;
comment?: string;
countries: Country[];
createdAt: Date;
currency: string | null;
currency?: string;
dataSource: DataSource;
dateOfFirstActivity?: Date;
id: string;
isin: string | null;
name: string | null;
scraperConfiguration?: ScraperConfiguration | null;
figi?: string;
figiComposite?: string;
figiShareClass?: string;
isin?: string;
name?: string;
scraperConfiguration?: ScraperConfiguration;
sectors: Sector[];
symbol: string;
symbolMapping?: { [key: string]: string };

Loading…
Cancel
Save