From 3cad76b6f81f8da06428bc480ea901f4081cab65 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 11 Feb 2025 14:57:49 +0100 Subject: [PATCH] Fix Tags on orders (SymbolProfile) --- apps/api/src/app/order/order.service.ts | 35 ++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 1f3c738f2..049daeeaa 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -27,8 +27,7 @@ import { Order, Prisma, Tag, - Type as ActivityType, - SymbolProfile + Type as ActivityType } from '@prisma/client'; import { Big } from 'big.js'; import { endOfToday, isAfter } from 'date-fns'; @@ -54,22 +53,34 @@ export class OrderService { userId, tags }: { tags: Tag[]; userId: string } & AssetProfileIdentifier) { - const symbolProfile: SymbolProfile = - await this.symbolProfileService.getSymbolProfiles([ - { - dataSource, - symbol - } - ])[0]; + const promis = await this.symbolProfileService.getSymbolProfiles([ + { + dataSource, + symbol + } + ]); + const symbolProfile: EnhancedSymbolProfile = promis[0]; const result = await this.symbolProfileService.updateSymbolProfile({ assetClass: symbolProfile.assetClass, assetSubClass: symbolProfile.assetSubClass, - countries: symbolProfile.countries, + countries: symbolProfile.countries.reduce( + (all, v) => [...all, { code: v.code, weight: v.weight }], + [] + ), currency: symbolProfile.currency, dataSource, - holdings: symbolProfile.holdings, + holdings: symbolProfile.holdings.reduce( + (all, v) => [ + ...all, + { name: v.name, weight: v.allocationInPercentage } + ], + [] + ), name: symbolProfile.name, - sectors: symbolProfile.sectors, + sectors: symbolProfile.sectors.reduce( + (all, v) => [...all, { name: v.name, weight: v.weight }], + [] + ), symbol, tags: { connectOrCreate: tags.map(({ id, name }) => {