* Rename Money/Url to Currency/Link * regenerate front types * renaming money/url field types * fix double text * fix tests * fix server tests * fix generate-target-column-map * fix currency convert * fix: tests --------- Co-authored-by: Jérémy Magrin <jeremy.magrin@gmail.com>
31 lines
958 B
TypeScript
31 lines
958 B
TypeScript
export const convertCurrencyToCurrencyMicros = (
|
|
currencyAmount: number | undefined,
|
|
) => {
|
|
if (!currencyAmount) {
|
|
return undefined;
|
|
}
|
|
const currencyAmountAsNumber = +currencyAmount;
|
|
if (isNaN(currencyAmountAsNumber)) {
|
|
throw new Error(`Cannot convert ${currencyAmount} to micros`);
|
|
}
|
|
const currencyAmountAsMicros = currencyAmountAsNumber * 1000000;
|
|
if (currencyAmountAsMicros % 1 !== 0) {
|
|
throw new Error(`Cannot convert ${currencyAmount} to micros`);
|
|
}
|
|
return currencyAmountAsMicros;
|
|
};
|
|
|
|
export const convertCurrencyMicrosToCurrency = (
|
|
currencyAmountMicros: number | undefined,
|
|
) => {
|
|
if (!currencyAmountMicros) {
|
|
return undefined;
|
|
}
|
|
const currencyAmountMicrosAsNumber = +currencyAmountMicros;
|
|
if (isNaN(currencyAmountMicrosAsNumber)) {
|
|
throw new Error(`Cannot convert ${currencyAmountMicros} to currency`);
|
|
}
|
|
const currencyAmount = currencyAmountMicrosAsNumber / 1000000;
|
|
return currencyAmount;
|
|
};
|