Browse Source

feat(api): make inclusion of cash orders optional

pull/6171/head
KenTandrian 6 days ago
parent
commit
94d2fa47c0
  1. 49
      apps/api/src/app/order/order.service.ts

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

@ -743,47 +743,50 @@ export class OrderService {
/** /**
* Retrieves all orders required for the portfolio calculator, including both standard asset orders * Retrieves all orders required for the portfolio calculator, including both standard asset orders
* and synthetic orders representing cash activities. * and optional synthetic orders representing cash activities.
*
* @param filters - Optional filters to apply to the orders.
* @param userCurrency - The base currency of the user.
* @param userId - The ID of the user.
* @returns An object containing the combined list of activities and the total count.
*/ */
@LogPerformance @LogPerformance
public async getOrdersForPortfolioCalculator({ public async getOrdersForPortfolioCalculator({
filters, filters,
userCurrency, userCurrency,
userId userId,
withCash = false
}: { }: {
/** Optional filters to apply to the orders. */
filters?: Filter[]; filters?: Filter[];
/** The base currency of the user. */
userCurrency: string; userCurrency: string;
/** The ID of the user. */
userId: string; userId: string;
/** Whether to include cash activities in the result. */
withCash?: boolean;
}) { }) {
const nonCashOrders = await this.getOrders({ const orders = await this.getOrders({
filters, filters,
userCurrency, userCurrency,
userId, userId,
withExcludedAccountsAndActivities: false // TODO withExcludedAccountsAndActivities: false // TODO
}); });
const cashDetails = await this.accountService.getCashDetails({ if (withCash) {
filters, const cashDetails = await this.accountService.getCashDetails({
userId, filters,
currency: userCurrency userId,
}); currency: userCurrency
});
const cashOrders = await this.getCashOrders({ const cashOrders = await this.getCashOrders({
cashDetails, cashDetails,
filters, filters,
userCurrency, userCurrency,
userId userId
}); });
return { orders.activities.push(...cashOrders.activities);
activities: [...nonCashOrders.activities, ...cashOrders.activities], orders.count += cashOrders.count;
count: nonCashOrders.count + cashOrders.count }
};
return orders;
} }
public async getStatisticsByCurrency( public async getStatisticsByCurrency(

Loading…
Cancel
Save