mirror of https://github.com/ghostfolio/ghostfolio
Browse Source
* Support derived currencies in currency validation * Update changelogpull/3526/head^2
Thomas Kaul
7 months ago
committed by
GitHub
9 changed files with 92 additions and 14 deletions
@ -0,0 +1,44 @@ |
|||
import { DERIVED_CURRENCIES } from '@ghostfolio/common/config'; |
|||
|
|||
import { |
|||
registerDecorator, |
|||
ValidationOptions, |
|||
ValidatorConstraint, |
|||
ValidatorConstraintInterface, |
|||
ValidationArguments |
|||
} from 'class-validator'; |
|||
import { isISO4217CurrencyCode } from 'class-validator'; |
|||
|
|||
export function IsCurrencyCode(validationOptions?: ValidationOptions) { |
|||
return function (object: Object, propertyName: string) { |
|||
registerDecorator({ |
|||
propertyName, |
|||
constraints: [], |
|||
options: validationOptions, |
|||
target: object.constructor, |
|||
validator: IsExtendedCurrencyConstraint |
|||
}); |
|||
}; |
|||
} |
|||
|
|||
@ValidatorConstraint({ async: false }) |
|||
export class IsExtendedCurrencyConstraint |
|||
implements ValidatorConstraintInterface |
|||
{ |
|||
public defaultMessage(args: ValidationArguments) { |
|||
return '$value 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
|
|||
return ( |
|||
isISO4217CurrencyCode(currency) || |
|||
[ |
|||
...DERIVED_CURRENCIES.map((derivedCurrency) => { |
|||
return derivedCurrency.currency; |
|||
}), |
|||
'USX' |
|||
].includes(currency) |
|||
); |
|||
} |
|||
} |
@ -0,0 +1,30 @@ |
|||
{ |
|||
"meta": { |
|||
"date": "2024-06-28T00:00:00.000Z", |
|||
"version": "dev" |
|||
}, |
|||
"accounts": [ |
|||
{ |
|||
"balance": 2000, |
|||
"currency": "USD", |
|||
"id": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", |
|||
"isExcluded": false, |
|||
"name": "My Online Trading Account", |
|||
"platformId": null |
|||
} |
|||
], |
|||
"activities": [ |
|||
{ |
|||
"accountId": "b2d3fe1d-d6a8-41a3-be39-07ef5e9480f0", |
|||
"comment": null, |
|||
"fee": 0, |
|||
"quantity": 5, |
|||
"type": "BUY", |
|||
"unitPrice": 10875.00, |
|||
"currency": "ZAc", |
|||
"dataSource": "YAHOO", |
|||
"date": "2024-06-27T22:00:00.000Z", |
|||
"symbol": "JSE.JO" |
|||
} |
|||
] |
|||
} |
Loading…
Reference in new issue