From 6bb85c4fb80ff0bf6d300cf6d662baba8ef952d5 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 2 May 2025 16:09:27 +0200 Subject: [PATCH] Bugfix/allow GBp in currency code validation (#4640) * Allow GBp in currency code validation * Update changelog --- CHANGELOG.md | 4 ++++ apps/api/src/validators/is-currency-code.ts | 16 +++++----------- libs/common/src/lib/helper.ts | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d40df6fb8..984e7b089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the language localization for Français (`fr`) +### Fixed + +- Fixed the currency code validation by allowing `GBp` + ## 2.158.0 - 2025-04-30 ### Added diff --git a/apps/api/src/validators/is-currency-code.ts b/apps/api/src/validators/is-currency-code.ts index d04da7808..771818b05 100644 --- a/apps/api/src/validators/is-currency-code.ts +++ b/apps/api/src/validators/is-currency-code.ts @@ -1,4 +1,4 @@ -import { DERIVED_CURRENCIES } from '@ghostfolio/common/config'; +import { isDerivedCurrency } from '@ghostfolio/common/helper'; import { registerDecorator, @@ -28,17 +28,11 @@ export class IsExtendedCurrencyConstraint return '$property must be a valid ISO4217 currency code'; } - public validate(currency: any) { - // Return true if currency is a standard ISO 4217 code or a derived currency + public validate(currency: string) { + // Return true if currency is a derived currency or a standard ISO 4217 code return ( - this.isUpperCase(currency) && - (isISO4217CurrencyCode(currency) || - [ - ...DERIVED_CURRENCIES.map((derivedCurrency) => { - return derivedCurrency.currency; - }), - 'USX' - ].includes(currency)) + isDerivedCurrency(currency) || + (this.isUpperCase(currency) && isISO4217CurrencyCode(currency)) ); } diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts index e5104a991..e5dc187ff 100644 --- a/libs/common/src/lib/helper.ts +++ b/libs/common/src/lib/helper.ts @@ -349,7 +349,7 @@ export function isDerivedCurrency(aCurrency: string) { return true; } - return DERIVED_CURRENCIES.find(({ currency }) => { + return DERIVED_CURRENCIES.some(({ currency }) => { return currency === aCurrency; }); }