Browse Source

Fix Order services

pull/5027/head
Dan 9 months ago
parent
commit
db50adc0e8
  1. 51
      apps/api/src/app/order/order.service.ts

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

@ -27,7 +27,8 @@ 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';
@ -50,34 +51,40 @@ export class OrderService {
public async assignTags({ public async assignTags({
dataSource, dataSource,
symbol, symbol,
tags, tags
userId
}: { tags: Tag[]; userId: string } & AssetProfileIdentifier) { }: { tags: Tag[]; userId: string } & AssetProfileIdentifier) {
const orders = await this.prismaService.order.findMany({ const symbolProfile: SymbolProfile =
where: { await this.symbolProfileService.getSymbolProfiles([
userId, {
SymbolProfile: {
dataSource, dataSource,
symbol symbol
} }
} ])[0];
}); return await this.symbolProfileService.updateSymbolProfile({
assetClass: symbolProfile.assetClass,
return Promise.all( assetSubClass: symbolProfile.assetSubClass,
orders.map(({ id }) => countries: symbolProfile.countries,
this.prismaService.order.update({ currency: symbolProfile.currency,
data: { dataSource,
holdings: symbolProfile.holdings,
name: symbolProfile.name,
sectors: symbolProfile.sectors,
symbol,
tags: { tags: {
// The set operation replaces all existing connections with the provided ones connectOrCreate: tags.map(({ id, name }) => {
set: tags.map(({ id }) => { return {
return { id }; create: {
}) id,
} name
}, },
where: { id } where: {
id
}
};
}) })
) },
); url: symbolProfile.url
});
} }
public async createOrder( public async createOrder(

Loading…
Cancel
Save