Browse Source

Filter order types in portfolio service

pull/547/head
Thomas 4 years ago
parent
commit
454b578c7f
  1. 14
      apps/api/src/app/order/order.service.ts
  2. 17
      apps/api/src/app/portfolio/portfolio.service.ts

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

@ -3,7 +3,7 @@ import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.se
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { OrderWithAccount } from '@ghostfolio/common/types';
import { Injectable } from '@nestjs/common';
import { DataSource, Order, Prisma } from '@prisma/client';
import { DataSource, Order, Prisma, Type as TypeOfOrder } from '@prisma/client';
import Big from 'big.js';
import { endOfToday, isAfter } from 'date-fns';
@ -85,9 +85,11 @@ export class OrderService {
public async getOrders({
includeDrafts = false,
types,
userId
}: {
includeDrafts?: boolean;
types?: TypeOfOrder[];
userId: string;
}) {
const where: Prisma.OrderWhereInput = { userId };
@ -96,6 +98,16 @@ export class OrderService {
where.isDraft = false;
}
if (types) {
where.OR = types.map((type) => {
return {
type: {
equals: type
}
};
});
}
return (
await this.orders({
where,

17
apps/api/src/app/portfolio/portfolio.service.ts

@ -369,9 +369,9 @@ export class PortfolioService {
): Promise<PortfolioPositionDetail> {
const userId = await this.getUserId(aImpersonationId, this.request.user.id);
const orders = (await this.orderService.getOrders({ userId })).filter(
(order) => order.symbol === aSymbol
);
const orders = (
await this.orderService.getOrders({ userId, types: ['BUY', 'SELL'] })
).filter((order) => order.symbol === aSymbol);
if (orders.length <= 0) {
return {
@ -828,7 +828,10 @@ export class PortfolioService {
userId,
currency
);
const orders = await this.orderService.getOrders({ userId });
const orders = await this.orderService.getOrders({
userId,
types: ['BUY', 'SELL']
});
const dividend = this.getDividend(orders).toNumber();
const fees = this.getFees(orders).toNumber();
const firstOrderDate = orders[0]?.date;
@ -994,7 +997,11 @@ export class PortfolioService {
transactionPoints: TransactionPoint[];
orders: OrderWithAccount[];
}> {
const orders = await this.orderService.getOrders({ includeDrafts, userId });
const orders = await this.orderService.getOrders({
includeDrafts,
userId,
types: ['BUY', 'SELL']
});
if (orders.length <= 0) {
return { transactionPoints: [], orders: [] };

Loading…
Cancel
Save