From 4fd952a3085a81d8f00f7fc0eaa8b763556144be Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 19 Jul 2025 11:04:20 +0200 Subject: [PATCH] Handle no accounts --- .../account-cluster-risk/current-investment.ts | 10 ++++++++++ .../rules/account-cluster-risk/single-account.ts | 14 +++++++++++--- apps/client/src/app/pages/i18n/i18n-page.html | 6 ++++++ 3 files changed, 27 insertions(+), 3 deletions(-) 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 06b2c5a8e..dbf3fee4d 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 @@ -37,6 +37,16 @@ export class AccountClusterRiskCurrentInvestment extends Rule { }; } + if (Object.keys(accounts).length === 0) { + return { + evaluation: this.i18nService.getTranslation({ + id: 'rule.accountClusterRiskCurrentInvestment.false.invalid', + languageCode: this.getLanguageCode() + }), + value: false + }; + } + let maxAccount: (typeof accounts)[0]; let totalInvestment = 0; diff --git a/apps/api/src/models/rules/account-cluster-risk/single-account.ts b/apps/api/src/models/rules/account-cluster-risk/single-account.ts index ea48f3538..6045e5892 100644 --- a/apps/api/src/models/rules/account-cluster-risk/single-account.ts +++ b/apps/api/src/models/rules/account-cluster-risk/single-account.ts @@ -22,9 +22,17 @@ export class AccountClusterRiskSingleAccount extends Rule { } public evaluate() { - const accounts: string[] = Object.keys(this.accounts); + const accountIds: string[] = Object.keys(this.accounts); - if (accounts.length === 1) { + if (accountIds.length === 0) { + return { + evaluation: this.i18nService.getTranslation({ + id: 'rule.accountClusterRiskSingleAccount.false.invalid', + languageCode: this.getLanguageCode() + }), + value: false + }; + } else if (accountIds.length === 1) { return { evaluation: this.i18nService.getTranslation({ id: 'rule.accountClusterRiskSingleAccount.false', @@ -39,7 +47,7 @@ export class AccountClusterRiskSingleAccount extends Rule { id: 'rule.accountClusterRiskSingleAccount.true', languageCode: this.getLanguageCode(), placeholders: { - accountsLength: accounts.length + accountsLength: accountIds.length } }), value: true diff --git a/apps/client/src/app/pages/i18n/i18n-page.html b/apps/client/src/app/pages/i18n/i18n-page.html index bb5a00cc0..26f0b8dbb 100644 --- a/apps/client/src/app/pages/i18n/i18n-page.html +++ b/apps/client/src/app/pages/i18n/i18n-page.html @@ -17,6 +17,9 @@ Over ${thresholdMax}% of your current investment is at ${maxAccountName} (${maxInvestmentRatio}%) +
  • + No accounts have been set up +
  • The major part of your current investment is at ${maxAccountName} (${maxInvestmentRatio}%) and does @@ -26,6 +29,9 @@
  • Your net worth is managed by a single account
  • +
  • + Your net worth is managed by 0 accounts +
  • Your net worth is managed by ${accountsLength} accounts