diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 48f175b30..6012f1384 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -77,6 +77,31 @@ export class OrderService { }); } + public getOrders({ + includeDrafts = false, + userId + }: { + includeDrafts?: boolean; + userId: string; + }) { + const where: Prisma.OrderWhereInput = { userId }; + + if (includeDrafts === false) { + where.isDraft = false; + } + + return this.orders({ + where, + include: { + // eslint-disable-next-line @typescript-eslint/naming-convention + Account: true, + // eslint-disable-next-line @typescript-eslint/naming-convention + SymbolProfile: true + }, + orderBy: { date: 'asc' } + }); + } + public async updateOrder(params: { where: Prisma.OrderWhereUniqueInput; data: Prisma.OrderUpdateInput; diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 7a7ec7ce6..333042bd1 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -159,7 +159,7 @@ export class PortfolioService { userId, currency ); - const orders = await this.getOrders({ userId }); + const orders = await this.orderService.getOrders({ userId }); const fees = this.getFees(orders); const totalBuy = this.getTotalByType(orders, currency, TypeOfOrder.BUY); @@ -266,7 +266,7 @@ export class PortfolioService { ): Promise { const userId = await this.getUserId(aImpersonationId); - const orders = (await this.getOrders({ userId })).filter( + const orders = (await this.orderService.getOrders({ userId })).filter( (order) => order.symbol === aSymbol ); @@ -692,7 +692,7 @@ export class PortfolioService { transactionPoints: TransactionPoint[]; orders: OrderWithAccount[]; }> { - const orders = await this.getOrders({ includeDrafts, userId }); + const orders = await this.orderService.getOrders({ includeDrafts, userId }); if (orders.length <= 0) { return { transactionPoints: [], orders: [] }; @@ -764,31 +764,6 @@ export class PortfolioService { return accounts; } - private getOrders({ - includeDrafts = false, - userId - }: { - includeDrafts?: boolean; - userId: string; - }) { - const where: Prisma.OrderWhereInput = { userId }; - - if (includeDrafts === false) { - where.isDraft = false; - } - - return this.orderService.orders({ - where, - include: { - // eslint-disable-next-line @typescript-eslint/naming-convention - Account: true, - // eslint-disable-next-line @typescript-eslint/naming-convention - SymbolProfile: true - }, - orderBy: { date: 'asc' } - }); - } - private async getUserId(aImpersonationId: string) { const impersonationUserId = await this.impersonationService.validateImpersonationId(