diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 8525878a0..a34848362 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/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, diff --git a/libs/common/src/lib/interfaces/enhanced-symbol-profile.interface.ts b/libs/common/src/lib/interfaces/enhanced-symbol-profile.interface.ts index 3bf914eaa..e9fe2f658 100644 --- a/libs/common/src/lib/interfaces/enhanced-symbol-profile.interface.ts +++ b/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 };