@lucaapp/service-utils 1.57.0 → 1.57.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,7 +15,7 @@ interface MoneyInterface<T extends SupportedCurrencies> {
|
|
|
15
15
|
isPositive(): boolean;
|
|
16
16
|
isNegative(): boolean;
|
|
17
17
|
}
|
|
18
|
-
export declare class Money<T extends SupportedCurrencies> implements MoneyInterface<T> {
|
|
18
|
+
export declare class Money<T extends SupportedCurrencies = SupportedCurrencies> implements MoneyInterface<T> {
|
|
19
19
|
readonly currency: T;
|
|
20
20
|
private readonly value;
|
|
21
21
|
static fromAmount<T extends SupportedCurrencies>(value: number, currency: T): Money<T>;
|
package/dist/lib/money/money.js
CHANGED
|
@@ -134,9 +134,13 @@ const moneyfiedGet = (model, key) => {
|
|
|
134
134
|
};
|
|
135
135
|
exports.moneyfiedGet = moneyfiedGet;
|
|
136
136
|
const moneyfiedSet = (model, key, value) => {
|
|
137
|
-
|
|
137
|
+
const modelCurrency = model.getDataValue('currency');
|
|
138
|
+
if (value?.currency && modelCurrency && value.currency !== modelCurrency) {
|
|
138
139
|
throw new TypeError('Currencies must match');
|
|
139
140
|
}
|
|
141
|
+
else if (value?.currency && !modelCurrency) {
|
|
142
|
+
model.setDataValue('currency', value.currency);
|
|
143
|
+
}
|
|
140
144
|
model.setDataValue(key, value?.getAmount());
|
|
141
145
|
};
|
|
142
146
|
exports.moneyfiedSet = moneyfiedSet;
|