Browse Source

Move getOrders() to order service

pull/265/head
Thomas 4 years ago
parent
commit
ad270e1b24
  1. 25
      apps/api/src/app/order/order.service.ts
  2. 31
      apps/api/src/app/portfolio/portfolio.service.ts

25
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;

31
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<PortfolioPositionDetail> {
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(

Loading…
Cancel
Save