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'; } from '@prisma/client';
import { Big } from 'big.js'; import { Big } from 'big.js';
import { endOfToday, isAfter } from 'date-fns'; import { endOfToday, isAfter } from 'date-fns';
import { groupBy } from 'lodash'; import { groupBy, uniqBy } from 'lodash';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { Activities } from './interfaces/activities.interface'; import { Activities } from './interfaces/activities.interface';
@ -320,7 +320,49 @@ export class OrderService {
this.prismaService.order.count({ where }) 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 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(); const value = new Big(order.quantity).mul(order.unitPrice).toNumber();
return { return {
@ -332,6 +374,27 @@ export class OrderService {
order.SymbolProfile.currency, order.SymbolProfile.currency,
userCurrency 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 // TODO: Use exchange rate of date
valueInBaseCurrency: this.exchangeRateDataService.toCurrency( valueInBaseCurrency: this.exchangeRateDataService.toCurrency(
value, value,

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

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

Loading…
Cancel
Save