Browse Source

Allow GBp in currency code validation

pull/4640/head
Thomas Kaul 4 months ago
parent
commit
f3b9161e40
  1. 16
      apps/api/src/validators/is-currency-code.ts
  2. 2
      libs/common/src/lib/helper.ts

16
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))
);
}

2
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;
});
}

Loading…
Cancel
Save