From 38c2baf943e6e0d2f2cd762cefd754e60c249ecc Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 16 Mar 2024 12:29:21 +0100 Subject: [PATCH] Feature/improve exception handling of current investments in various rules (#3156) * Improve exception handling * Update changelog --- CHANGELOG.md | 1 + .../models/rules/account-cluster-risk/current-investment.ts | 4 ++-- .../currency-cluster-risk/base-currency-current-investment.ts | 2 +- .../models/rules/currency-cluster-risk/current-investment.ts | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b1f613e..f2113955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the usability of the platform management in the admin control panel - Improved the usability of the tag management in the admin control panel +- Improved the exception handling of various rules in the _X-ray_ section ### Fixed diff --git a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts index 23d3307d..52f20a21 100644 --- a/apps/api/src/models/rules/account-cluster-risk/current-investment.ts +++ b/apps/api/src/models/rules/account-cluster-risk/current-investment.ts @@ -35,7 +35,7 @@ export class AccountClusterRiskCurrentInvestment extends Rule { }; } - let maxItem; + let maxItem: (typeof accounts)[0]; let totalInvestment = 0; for (const account of Object.values(accounts)) { @@ -52,7 +52,7 @@ export class AccountClusterRiskCurrentInvestment extends Rule { } } - const maxInvestmentRatio = maxItem.investment / totalInvestment; + const maxInvestmentRatio = maxItem?.investment / totalInvestment || 0; if (maxInvestmentRatio > ruleSettings.threshold) { return { diff --git a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts index a23a208c..a2bd44f4 100644 --- a/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts +++ b/apps/api/src/models/rules/currency-cluster-risk/base-currency-current-investment.ts @@ -43,7 +43,7 @@ export class CurrencyClusterRiskBaseCurrencyCurrentInvestment extends Rule { } }); - const maxValueRatio = maxItem.value / totalValue; + const maxValueRatio = maxItem?.value / totalValue || 0; if (maxValueRatio > ruleSettings.threshold) { return { @@ -52,7 +52,7 @@ export class CurrencyClusterRiskCurrentInvestment extends Rule { return { evaluation: `The major part of your current investment is in ${ - maxItem.groupKey + maxItem?.groupKey ?? ruleSettings.baseCurrency } (${(maxValueRatio * 100).toPrecision(3)}%) and does not exceed ${ ruleSettings.threshold * 100 }%`,