Browse Source
Feature/improve currency code validation (#4598)
* Improve currency code validation
* Update changelog
pull/4603/head
Thomas Kaul
6 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
18 additions and
8 deletions
-
CHANGELOG.md
-
apps/api/src/validators/is-currency-code.ts
|
@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 |
|
|
|
|
|
|
|
|
## Unreleased |
|
|
## Unreleased |
|
|
|
|
|
|
|
|
|
|
|
### Changed |
|
|
|
|
|
|
|
|
|
|
|
- Improved the error message of the currency code validation |
|
|
|
|
|
- Tightened the currency code validation by requiring uppercase letters |
|
|
|
|
|
|
|
|
### Fixed |
|
|
### Fixed |
|
|
|
|
|
|
|
|
- Improved the file selector of the activities import functionality to accept case-insensitive file extensions (`.CSV` and `.JSON`) |
|
|
- Improved the file selector of the activities import functionality to accept case-insensitive file extensions (`.CSV` and `.JSON`) |
|
|
|
@ -25,19 +25,24 @@ export class IsExtendedCurrencyConstraint |
|
|
implements ValidatorConstraintInterface |
|
|
implements ValidatorConstraintInterface |
|
|
{ |
|
|
{ |
|
|
public defaultMessage() { |
|
|
public defaultMessage() { |
|
|
return '$value must be a valid ISO4217 currency code'; |
|
|
return '$property must be a valid ISO4217 currency code'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public validate(currency: any) { |
|
|
public validate(currency: any) { |
|
|
// Return true if currency is a standard ISO 4217 code or a derived currency
|
|
|
// Return true if currency is a standard ISO 4217 code or a derived currency
|
|
|
return ( |
|
|
return ( |
|
|
isISO4217CurrencyCode(currency) || |
|
|
this.isUpperCase(currency) && |
|
|
|
|
|
(isISO4217CurrencyCode(currency) || |
|
|
[ |
|
|
[ |
|
|
...DERIVED_CURRENCIES.map((derivedCurrency) => { |
|
|
...DERIVED_CURRENCIES.map((derivedCurrency) => { |
|
|
return derivedCurrency.currency; |
|
|
return derivedCurrency.currency; |
|
|
}), |
|
|
}), |
|
|
'USX' |
|
|
'USX' |
|
|
].includes(currency) |
|
|
].includes(currency)) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private isUpperCase(aString: string) { |
|
|
|
|
|
return aString === aString?.toUpperCase(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|