From a3cdb2377661cbf04ace7e9c7b83888c5b37fd0e Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 18 Feb 2024 12:29:00 +0100 Subject: [PATCH] Feature/refactor query to filter activities of excluded accounts (#3016) * Refactor query to filter activities of excluded accounts * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/order/order.service.ts | 48 ++++++++++++------------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65a386edf..b3d9f3513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Improved the usability of the holdings table +- Refactored the query to filter activities of excluded accounts - Improved the language localization for German (`de`) - Upgraded `ng-extract-i18n-merge` from version `2.9.1` to `2.10.0` diff --git a/apps/api/src/app/order/order.service.ts b/apps/api/src/app/order/order.service.ts index 5a6beb0a4..e60309856 100644 --- a/apps/api/src/app/order/order.service.ts +++ b/apps/api/src/app/order/order.service.ts @@ -301,6 +301,12 @@ export class OrderService { }); } + if (withExcludedAccounts === false) { + where.Account = { + NOT: { isExcluded: true } + }; + } + const [orders, count] = await Promise.all([ this.orders({ orderBy, @@ -322,32 +328,24 @@ export class OrderService { this.prismaService.order.count({ where }) ]); - const activities = orders - .filter((order) => { - return ( - withExcludedAccounts || - !order.Account || - order.Account?.isExcluded === false - ); - }) - .map((order) => { - const value = new Big(order.quantity).mul(order.unitPrice).toNumber(); - - return { - ...order, + const activities = orders.map((order) => { + const value = new Big(order.quantity).mul(order.unitPrice).toNumber(); + + return { + ...order, + value, + feeInBaseCurrency: this.exchangeRateDataService.toCurrency( + order.fee, + order.SymbolProfile.currency, + userCurrency + ), + valueInBaseCurrency: this.exchangeRateDataService.toCurrency( value, - feeInBaseCurrency: this.exchangeRateDataService.toCurrency( - order.fee, - order.SymbolProfile.currency, - userCurrency - ), - valueInBaseCurrency: this.exchangeRateDataService.toCurrency( - value, - order.SymbolProfile.currency, - userCurrency - ) - }; - }); + order.SymbolProfile.currency, + userCurrency + ) + }; + }); return { activities, count }; }