Browse Source

Fix Tags on orders (SymbolProfile)

pull/5027/head
Dan 5 months ago
parent
commit
3cad76b6f8
  1. 35
      apps/api/src/app/order/order.service.ts

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

@ -27,8 +27,7 @@ import {
Order, Order,
Prisma, Prisma,
Tag, Tag,
Type as ActivityType, Type as ActivityType
SymbolProfile
} 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';
@ -54,22 +53,34 @@ export class OrderService {
userId, userId,
tags tags
}: { tags: Tag[]; userId: string } & AssetProfileIdentifier) { }: { tags: Tag[]; userId: string } & AssetProfileIdentifier) {
const symbolProfile: SymbolProfile = const promis = await this.symbolProfileService.getSymbolProfiles([
await this.symbolProfileService.getSymbolProfiles([ {
{ dataSource,
dataSource, symbol
symbol }
} ]);
])[0]; const symbolProfile: EnhancedSymbolProfile = promis[0];
const result = await this.symbolProfileService.updateSymbolProfile({ const result = await this.symbolProfileService.updateSymbolProfile({
assetClass: symbolProfile.assetClass, assetClass: symbolProfile.assetClass,
assetSubClass: symbolProfile.assetSubClass, assetSubClass: symbolProfile.assetSubClass,
countries: symbolProfile.countries, countries: symbolProfile.countries.reduce(
(all, v) => [...all, { code: v.code, weight: v.weight }],
[]
),
currency: symbolProfile.currency, currency: symbolProfile.currency,
dataSource, dataSource,
holdings: symbolProfile.holdings, holdings: symbolProfile.holdings.reduce(
(all, v) => [
...all,
{ name: v.name, weight: v.allocationInPercentage }
],
[]
),
name: symbolProfile.name, name: symbolProfile.name,
sectors: symbolProfile.sectors, sectors: symbolProfile.sectors.reduce(
(all, v) => [...all, { name: v.name, weight: v.weight }],
[]
),
symbol, symbol,
tags: { tags: {
connectOrCreate: tags.map(({ id, name }) => { connectOrCreate: tags.map(({ id, name }) => {

Loading…
Cancel
Save