@lyxa.ai/core 1.1.38 → 1.1.39
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.
- package/dist/libraries/mongo/models/cart.model.d.ts +0 -2
- package/dist/libraries/mongo/models/cart.model.js +0 -10
- package/dist/libraries/mongo/models/cart.model.js.map +1 -1
- package/dist/libraries/mongo/models/embedded/currency.model.d.ts +0 -1
- package/dist/libraries/mongo/models/embedded/currency.model.js +0 -5
- package/dist/libraries/mongo/models/embedded/currency.model.js.map +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/shared/currency.d.ts +4 -1
- package/dist/types/utilities/shared/currency.js +17 -13
- package/dist/types/utilities/shared/currency.js.map +1 -1
- package/dist/utilities/currency.d.ts +2 -6
- package/dist/utilities/currency.js +14 -52
- package/dist/utilities/currency.js.map +1 -1
- package/dist/utilities/pipelines/common-pipeline-functions.d.ts +2 -5
- package/dist/utilities/pipelines/common-pipeline-functions.js +23 -19
- package/dist/utilities/pipelines/common-pipeline-functions.js.map +1 -1
- package/dist/utilities/pipelines/product-pipeline-stages.d.ts +2 -2
- package/dist/utilities/pipelines/product-pipeline-stages.js +21 -29
- package/dist/utilities/pipelines/product-pipeline-stages.js.map +1 -1
- package/dist/utilities/shared/currency.d.ts +4 -1
- package/dist/utilities/shared/currency.js +17 -13
- package/dist/utilities/shared/currency.js.map +1 -1
- package/package.json +1 -1
|
@@ -68,8 +68,6 @@ let Cart = class Cart extends defaultClasses_1.TimeStamps {
|
|
|
68
68
|
cartId;
|
|
69
69
|
title;
|
|
70
70
|
exchangeRate;
|
|
71
|
-
roundTo;
|
|
72
|
-
secondaryRoundTo;
|
|
73
71
|
user;
|
|
74
72
|
parent;
|
|
75
73
|
shop;
|
|
@@ -95,14 +93,6 @@ __decorate([
|
|
|
95
93
|
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
96
94
|
__metadata("design:type", Number)
|
|
97
95
|
], Cart.prototype, "exchangeRate", void 0);
|
|
98
|
-
__decorate([
|
|
99
|
-
(0, typegoose_1.prop)({ type: Number, default: 0.01 }),
|
|
100
|
-
__metadata("design:type", Number)
|
|
101
|
-
], Cart.prototype, "roundTo", void 0);
|
|
102
|
-
__decorate([
|
|
103
|
-
(0, typegoose_1.prop)({ type: Number, default: 1000 }),
|
|
104
|
-
__metadata("design:type", Number)
|
|
105
|
-
], Cart.prototype, "secondaryRoundTo", void 0);
|
|
106
96
|
__decorate([
|
|
107
97
|
(0, typegoose_1.prop)({ required: true, ref: () => user_model_1.User }),
|
|
108
98
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cart.model.js","sourceRoot":"/","sources":["libraries/mongo/models/cart.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAqF;AACrF,6CAAoC;AACpC,iDAAwC;AACxC,4EAAqE;AACrE,kDAA8F;AAC9F,0DAAsE;AAEtE,6CAAoC;AACpC,uDAA6C;AAC7C,kEAAwE;AACxE,wBAA8B;AAC9B,0DAAiD;AAEjD,MAAa,QAAQ;IAEb,IAAI,CAAU;IAGd,UAAU,CAAc;IAGxB,MAAM,CAAU;IAGhB,QAAQ,CAAY;IAGpB,OAAO,CAAW;IAGlB,IAAI,CAAU;IAGd,cAAc,CAAW;IAGzB,sBAAsB,CAAU;CACvC;AAxBD,4BAwBC;AAtBO;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;sCAClB;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAU,EAAE,OAAO,EAAE,iBAAU,CAAC,MAAM,EAAE,CAAC;;4CACtD;AAGxB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,qBAAM,EAAE,CAAC;8BAC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ADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;;wCACR;AAOpB;IALN,IAAA,gBAAI,EAAC;QACL,GAAG,EAAE,GAAG,EAAE,CAAC,0BAAQ;QACnB,YAAY,EAAE,MAAM;QACpB,UAAU,EAAE,KAAK;KACjB,CAAC;;uCACgC;eAlDtB,IAAI;IA7BhB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE;YACd,UAAU,EAAE,OAAO;YACnB,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC1B,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC5B;QACD,OAAO,EAAE;YACR,UAAU,EAAE,oBAAQ,CAAC,KAAK;SAC1B;KACD,CAAC;IACD,IAAA,iBAAK,EAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAClB,IAAA,iBAAK,EAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAClB,IAAA,iBAAK,EAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACpB,IAAA,iBAAK,EACL,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EACpB;QACC,MAAM,EAAE,IAAI;QACZ,uBAAuB,EAAE;YACxB,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,iBAAU,CAAC,MAAM,EAAE,iBAAU,CAAC,MAAM,CAAC,EAAE;YACvD,SAAS,EAAE,IAAI;SACf;KACD,CACD;IACA,IAAA,eAAG,EAAO,MAAM,EAAE,KAAK,WAAW,IAAI;QAEtC,MAAM,0CAAwB,CAAC,IAAI,CAAC,IAAI,EAAE,YAAS,EAAE,QAAQ,CAAC,CAAC;QAE/D,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;GACW,IAAI,CAmDhB","sourcesContent":["import { prop, Ref, index, modelOptions, Severity, pre } from '@typegoose/typegoose';\nimport { Shop } from './shop.model';\nimport { Parent } from './parent.model';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { CartStatus, ChargeType, ItemType, PaymentPreference } from '../../../utilities/enum';\nimport { Address, RegularOrderAddress } from './shared/address.model';\nimport { Coupon } from './coupon.model';\nimport { User } from './user.model';\nimport { LineItem } from './line-item.model';\nimport { handlePreSaveForUniqueId } from '../utilities/unique-id.hooks';\nimport { CartModel } from '.';\nimport { Charge } from './embedded/charge.model';\n\nexport class ShopSnap {\n\t@prop({ required: true, type: String })\n\tpublic name!: string;\n\n\t@prop({ required: true, type: String, enum: ChargeType, default: ChargeType.CUSTOM })\n\tpublic chargeType!: ChargeType;\n\n\t@prop({ required: true, type: Charge })\n\tpublic charge!: Charge;\n\n\t@prop({ required: true, type: String, enum: ItemType })\n\tpublic itemType!: ItemType;\n\n\t@prop({ required: true, type: Address })\n\tpublic address!: Address;\n\n\t@prop({ type: String })\n\tpublic logo?: string;\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isShopDelivery?: boolean;\n\n\t@prop({ type: Number, default: 10 })\n\tpublic defaultPreparationTime?: number;\n}\n\n@modelOptions({\n\tschemaOptions: {\n\t\tcollection: 'carts',\n\t\ttoJSON: { virtuals: true },\n\t\ttoObject: { virtuals: true },\n\t},\n\toptions: {\n\t\tallowMixed: Severity.ALLOW,\n\t},\n})\n@index({ user: 1 })\n@index({ shop: 1 })\n@index({ status: 1 })\n@index(\n\t{ user: 1, shop: 1 },\n\t{\n\t\tunique: true,\n\t\tpartialFilterExpression: {\n\t\t\tstatus: { $in: [CartStatus.ACTIVE, CartStatus.LOCKED] },\n\t\t\tdeletedAt: null,\n\t\t},\n\t}\n)\n@pre<Cart>('save', async function (next) {\n\t// Generate unique id if not exists\n\tawait handlePreSaveForUniqueId.call(this, CartModel, 'cartId');\n\n\tnext();\n})\nexport class Cart extends TimeStamps {\n\t@prop({ type: String, unique: true, index: true })\n\tpublic cartId: string;\n\n\t@prop({ trim: true, maxlength: 100 })\n\tpublic title?: string;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic exchangeRate?: number;\n\n\t@prop({ required: true, ref: () => User })\n\tpublic user!: Ref<User>;\n\n\t@prop({ required: true, ref: () => Parent })\n\tpublic parent: Ref<Parent>;\n\n\t@prop({ required: true, ref: () => Shop })\n\tpublic shop!: Ref<Shop>;\n\n\t@prop({ type: ShopSnap })\n\tpublic shopSnap?: ShopSnap;\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isGroupOrder?: boolean;\n\n\t@prop({ type: String, enum: PaymentPreference })\n\tpublic paymentPreference?: PaymentPreference;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic spendingLimitForGuest?: number;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic secondarySpendingLimitForGuest?: number;\n\n\t@prop({\n\t\tenum: CartStatus,\n\t\ttype: String,\n\t\tdefault: CartStatus.ACTIVE,\n\t\trequired: true,\n\t})\n\tpublic status!: CartStatus;\n\n\t@prop({ type: String, trim: true })\n\tpublic couponCode?: string;\n\n\t@prop({\n\t\tref: () => LineItem,\n\t\tforeignField: 'cart',\n\t\tlocalField: '_id',\n\t})\n\tpublic lineItems: Ref<LineItem>[];\n}\n"]}
|
|
@@ -15,7 +15,6 @@ class Currency {
|
|
|
15
15
|
symbol;
|
|
16
16
|
name;
|
|
17
17
|
code;
|
|
18
|
-
roundTo;
|
|
19
18
|
}
|
|
20
19
|
exports.Currency = Currency;
|
|
21
20
|
__decorate([
|
|
@@ -30,8 +29,4 @@ __decorate([
|
|
|
30
29
|
(0, typegoose_1.prop)({ type: String }),
|
|
31
30
|
__metadata("design:type", String)
|
|
32
31
|
], Currency.prototype, "code", void 0);
|
|
33
|
-
__decorate([
|
|
34
|
-
(0, typegoose_1.prop)({ type: Number, default: 0.01 }),
|
|
35
|
-
__metadata("design:type", Number)
|
|
36
|
-
], Currency.prototype, "roundTo", void 0);
|
|
37
32
|
//# sourceMappingURL=currency.model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/currency.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,QAAQ;IAEb,MAAM,CAAU;IAGhB,IAAI,CAAU;IAGd,IAAI,CAAU;
|
|
1
|
+
{"version":3,"file":"currency.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/currency.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,QAAQ;IAEb,MAAM,CAAU;IAGhB,IAAI,CAAU;IAGd,IAAI,CAAU;CACrB;AATD,4BASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wCACA;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;sCAClB;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;sCACF","sourcesContent":["import { prop } from '@typegoose/typegoose';\n\nexport class Currency {\n\t@prop({ type: String })\n\tpublic symbol?: string;\n\n\t@prop({ required: true, type: String })\n\tpublic name!: string;\n\n\t@prop({ type: String })\n\tpublic code?: string;\n}\n"]}
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
export declare const BaseCurrencyRoundTo = 0.01;
|
|
2
|
+
export declare const SecondaryCurrencyRoundTo = 1000;
|
|
1
3
|
export declare const roundCurrencySync: (amount: number, roundingFactor: number) => number;
|
|
2
|
-
export declare const
|
|
4
|
+
export declare const roundBaseCurrency: (amount: number) => number;
|
|
5
|
+
export declare const roundSecondaryCurrency: (amount: number) => number;
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.roundSecondaryCurrency = exports.roundBaseCurrency = exports.roundCurrencySync = exports.SecondaryCurrencyRoundTo = exports.BaseCurrencyRoundTo = void 0;
|
|
4
|
+
exports.BaseCurrencyRoundTo = 0.01;
|
|
5
|
+
exports.SecondaryCurrencyRoundTo = 1000;
|
|
4
6
|
const roundCurrencySync = (amount, roundingFactor) => {
|
|
5
|
-
if (amount
|
|
7
|
+
if (typeof amount !== 'number' ||
|
|
8
|
+
isNaN(amount) ||
|
|
9
|
+
typeof roundingFactor !== 'number' ||
|
|
10
|
+
roundingFactor <= 0 ||
|
|
11
|
+
amount === 0) {
|
|
6
12
|
return 0;
|
|
7
|
-
|
|
13
|
+
}
|
|
8
14
|
const decimals = (roundingFactor.toString().split('.')[1] || '').length;
|
|
15
|
+
const rounded = Math.round(amount / roundingFactor) * roundingFactor;
|
|
9
16
|
return Number(rounded.toFixed(decimals));
|
|
10
17
|
};
|
|
11
18
|
exports.roundCurrencySync = roundCurrencySync;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (!roundTo)
|
|
19
|
-
return amount;
|
|
20
|
-
return (0, exports.roundCurrencySync)(amount, roundTo);
|
|
19
|
+
const roundBaseCurrency = (amount) => {
|
|
20
|
+
return (0, exports.roundCurrencySync)(amount, exports.BaseCurrencyRoundTo);
|
|
21
|
+
};
|
|
22
|
+
exports.roundBaseCurrency = roundBaseCurrency;
|
|
23
|
+
const roundSecondaryCurrency = (amount) => {
|
|
24
|
+
return (0, exports.roundCurrencySync)(amount, exports.SecondaryCurrencyRoundTo);
|
|
21
25
|
};
|
|
22
|
-
exports.
|
|
26
|
+
exports.roundSecondaryCurrency = roundSecondaryCurrency;
|
|
23
27
|
//# sourceMappingURL=currency.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/shared/currency.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/shared/currency.ts"],"names":[],"mappings":";;;AACa,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAC3B,QAAA,wBAAwB,GAAG,IAAI,CAAC;AAGtC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,cAAsB,EAAU,EAAE;IACnF,IACC,OAAO,MAAM,KAAK,QAAQ;QAC1B,KAAK,CAAC,MAAM,CAAC;QACb,OAAO,cAAc,KAAK,QAAQ;QAClC,cAAc,IAAI,CAAC;QACnB,MAAM,KAAK,CAAC,EACX,CAAC;QACF,OAAO,CAAC,CAAC;IACV,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACxE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,GAAG,cAAc,CAAC;IAErE,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC;AAfW,QAAA,iBAAiB,qBAe5B;AAGK,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAU,EAAE;IAC3D,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,2BAAmB,CAAC,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAU,EAAE;IAChE,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,gCAAwB,CAAC,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC","sourcesContent":["// === Currency Rounding Constants ===\nexport const BaseCurrencyRoundTo = 0.01;\nexport const SecondaryCurrencyRoundTo = 1000;\n\n// === Safely rounds a number to the nearest rounding unit ===\nexport const roundCurrencySync = (amount: number, roundingFactor: number): number => {\n\tif (\n\t\ttypeof amount !== 'number' ||\n\t\tisNaN(amount) ||\n\t\ttypeof roundingFactor !== 'number' ||\n\t\troundingFactor <= 0 ||\n\t\tamount === 0\n\t) {\n\t\treturn 0;\n\t}\n\n\tconst decimals = (roundingFactor.toString().split('.')[1] || '').length;\n\tconst rounded = Math.round(amount / roundingFactor) * roundingFactor;\n\n\treturn Number(rounded.toFixed(decimals));\n};\n\n// === Specific rounding functions for base and secondary currencies ===\nexport const roundBaseCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, BaseCurrencyRoundTo);\n};\n\nexport const roundSecondaryCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, SecondaryCurrencyRoundTo);\n};\n"]}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { PaidCurrency } from './enum';
|
|
2
|
-
export declare const getRoundingFactor: (currency: PaidCurrency) => Promise<number>;
|
|
3
1
|
export declare const getExchangeRate: () => Promise<number>;
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const convertToSecondary: (amount: number, exchangeRate?: number, roundTo?: number) => Promise<number>;
|
|
7
|
-
export declare const convertToSecondarySync: (price: number, exchangeRate: number, roundTo: number) => number | undefined;
|
|
2
|
+
export declare const convertToBase: (amount: number) => Promise<number>;
|
|
3
|
+
export declare const convertToSecondary: (amount: number) => Promise<number>;
|
|
@@ -1,67 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.convertToSecondary = exports.convertToBase = exports.getExchangeRate = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const DEFAULT_EXCHANGE_RATE = 1;
|
|
8
|
-
const getRoundingFactor = async (currency) => {
|
|
9
|
-
const setting = (await (0, __1.getLibraries)().getCachedSettingsService().getSettings());
|
|
10
|
-
const currencySetting = setting.currencySetting;
|
|
11
|
-
let roundingFactor;
|
|
12
|
-
if (currencySetting) {
|
|
13
|
-
switch (currency) {
|
|
14
|
-
case enum_1.PaidCurrency.BASE:
|
|
15
|
-
roundingFactor = currencySetting.baseCurrency?.roundTo;
|
|
16
|
-
break;
|
|
17
|
-
case enum_1.PaidCurrency.SECONDARY:
|
|
18
|
-
roundingFactor = currencySetting.secondaryCurrency?.roundTo;
|
|
19
|
-
break;
|
|
20
|
-
default:
|
|
21
|
-
roundingFactor = DEFAULT_ROUNDING_FACTOR;
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return roundingFactor || DEFAULT_ROUNDING_FACTOR;
|
|
26
|
-
};
|
|
27
|
-
exports.getRoundingFactor = getRoundingFactor;
|
|
5
|
+
const shared_1 = require("./shared");
|
|
6
|
+
const DEFAULT_EXCHANGE_RATE = 0;
|
|
28
7
|
const getExchangeRate = async () => {
|
|
29
8
|
const settings = (await (0, __1.getLibraries)().getCachedSettingsService().getSettings());
|
|
30
9
|
const currencySetting = settings.currencySetting;
|
|
31
10
|
return currencySetting?.exchangeRate || DEFAULT_EXCHANGE_RATE;
|
|
32
11
|
};
|
|
33
12
|
exports.getExchangeRate = getExchangeRate;
|
|
34
|
-
const
|
|
35
|
-
if (amount
|
|
36
|
-
return 0;
|
|
37
|
-
roundingFactor = roundingFactor ?? (await (0, exports.getRoundingFactor)(currency));
|
|
38
|
-
return (0, exports.roundCurrencySync)(amount, roundingFactor);
|
|
39
|
-
};
|
|
40
|
-
exports.roundCurrency = roundCurrency;
|
|
41
|
-
const roundCurrencySync = (amount, roundingFactor) => {
|
|
42
|
-
if (amount == 0)
|
|
13
|
+
const convertToBase = async (amount) => {
|
|
14
|
+
if (typeof amount !== 'number' || isNaN(amount)) {
|
|
43
15
|
return 0;
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
return
|
|
16
|
+
}
|
|
17
|
+
const exchangeRate = await (0, exports.getExchangeRate)();
|
|
18
|
+
return (0, shared_1.roundBaseCurrency)(amount / exchangeRate);
|
|
47
19
|
};
|
|
48
|
-
exports.
|
|
49
|
-
const convertToSecondary = async (amount
|
|
50
|
-
if (amount
|
|
20
|
+
exports.convertToBase = convertToBase;
|
|
21
|
+
const convertToSecondary = async (amount) => {
|
|
22
|
+
if (typeof amount !== 'number' || isNaN(amount)) {
|
|
51
23
|
return 0;
|
|
52
|
-
|
|
53
|
-
|
|
24
|
+
}
|
|
25
|
+
const exchangeRate = await (0, exports.getExchangeRate)();
|
|
26
|
+
return (0, shared_1.roundSecondaryCurrency)(amount * exchangeRate);
|
|
54
27
|
};
|
|
55
28
|
exports.convertToSecondary = convertToSecondary;
|
|
56
|
-
const convertToSecondarySync = (price, exchangeRate, roundTo) => {
|
|
57
|
-
if (price == 0)
|
|
58
|
-
return 0;
|
|
59
|
-
if (price == null)
|
|
60
|
-
return undefined;
|
|
61
|
-
const amount = price * exchangeRate;
|
|
62
|
-
if (!roundTo)
|
|
63
|
-
return amount;
|
|
64
|
-
return (0, exports.roundCurrencySync)(amount, roundTo);
|
|
65
|
-
};
|
|
66
|
-
exports.convertToSecondarySync = convertToSecondarySync;
|
|
67
29
|
//# sourceMappingURL=currency.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/currency.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/currency.ts"],"names":[],"mappings":";;;AAAA,0BAAkC;AAElC,qCAAqE;AAErE,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEzB,MAAM,eAAe,GAAG,KAAK,IAAqB,EAAE;IAC1D,MAAM,QAAQ,GAAG,CAAC,MAAM,IAAA,gBAAY,GAAE,CAAC,wBAAwB,EAAE,CAAC,WAAW,EAAE,CAAY,CAAC;IAC5F,MAAM,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;IACjD,OAAO,eAAe,EAAE,YAAY,IAAI,qBAAqB,CAAC;AAC/D,CAAC,CAAC;AAJW,QAAA,eAAe,mBAI1B;AAEK,MAAM,aAAa,GAAG,KAAK,EAAE,MAAc,EAAmB,EAAE;IACtE,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACjD,OAAO,CAAC,CAAC;IACV,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,IAAA,uBAAe,GAAE,CAAC;IAC7C,OAAO,IAAA,0BAAiB,EAAC,MAAM,GAAG,YAAY,CAAC,CAAC;AACjD,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB;AAEK,MAAM,kBAAkB,GAAG,KAAK,EAAE,MAAc,EAAmB,EAAE;IAC3E,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QACjD,OAAO,CAAC,CAAC;IACV,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,IAAA,uBAAe,GAAE,CAAC;IAC7C,OAAO,IAAA,+BAAsB,EAAC,MAAM,GAAG,YAAY,CAAC,CAAC;AACtD,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B","sourcesContent":["import { getLibraries } from '..';\nimport { Setting } from '../libraries/mongo/models';\nimport { roundBaseCurrency, roundSecondaryCurrency } from './shared';\n\nconst DEFAULT_EXCHANGE_RATE = 0;\n\nexport const getExchangeRate = async (): Promise<number> => {\n\tconst settings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\tconst currencySetting = settings.currencySetting;\n\treturn currencySetting?.exchangeRate || DEFAULT_EXCHANGE_RATE;\n};\n\nexport const convertToBase = async (amount: number): Promise<number> => {\n\tif (typeof amount !== 'number' || isNaN(amount)) {\n\t\treturn 0;\n\t}\n\n\tconst exchangeRate = await getExchangeRate();\n\treturn roundBaseCurrency(amount / exchangeRate);\n};\n\nexport const convertToSecondary = async (amount: number): Promise<number> => {\n\tif (typeof amount !== 'number' || isNaN(amount)) {\n\t\treturn 0;\n\t}\n\n\tconst exchangeRate = await getExchangeRate();\n\treturn roundSecondaryCurrency(amount * exchangeRate);\n};\n"]}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
|
|
3
|
-
exchangeRate: number;
|
|
4
|
-
roundTo: number;
|
|
5
|
-
}) => any;
|
|
1
|
+
export declare const getRoundBaseCurrencyStage: (value: any) => Record<string, any>;
|
|
2
|
+
export declare const getRoundSecondaryCurrencyStage: (value: any) => Record<string, any>;
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
3
|
+
exports.getRoundSecondaryCurrencyStage = exports.getRoundBaseCurrencyStage = void 0;
|
|
4
|
+
const getRoundBaseCurrencyStage = (value) => {
|
|
5
5
|
return {
|
|
6
6
|
$cond: [
|
|
7
|
-
{ $
|
|
7
|
+
{ $ne: [value, null] },
|
|
8
8
|
{
|
|
9
|
-
$
|
|
10
|
-
body: function (price, exchangeRate, roundTo) {
|
|
11
|
-
if (price == null)
|
|
12
|
-
return null;
|
|
13
|
-
const amount = price * exchangeRate;
|
|
14
|
-
if (!roundTo)
|
|
15
|
-
return amount;
|
|
16
|
-
const rounded = Math.ceil(amount / roundTo) * roundTo;
|
|
17
|
-
const decimals = (roundTo.toString().split('.')[1] || '').length;
|
|
18
|
-
return Number(rounded.toFixed(decimals));
|
|
19
|
-
}.toString(),
|
|
20
|
-
args: [valuePath, exchangeRate, roundTo],
|
|
21
|
-
lang: 'js',
|
|
22
|
-
},
|
|
9
|
+
$round: [value, 2],
|
|
23
10
|
},
|
|
24
|
-
|
|
11
|
+
0,
|
|
25
12
|
],
|
|
26
13
|
};
|
|
27
14
|
};
|
|
28
|
-
exports.
|
|
15
|
+
exports.getRoundBaseCurrencyStage = getRoundBaseCurrencyStage;
|
|
16
|
+
const getRoundSecondaryCurrencyStage = (value) => {
|
|
17
|
+
return {
|
|
18
|
+
$cond: [
|
|
19
|
+
{ $ne: [value, null] },
|
|
20
|
+
{
|
|
21
|
+
$multiply: [
|
|
22
|
+
{
|
|
23
|
+
$round: [{ $divide: [value, 1000] }, 0],
|
|
24
|
+
},
|
|
25
|
+
1000,
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
0,
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
exports.getRoundSecondaryCurrencyStage = getRoundSecondaryCurrencyStage;
|
|
29
33
|
//# sourceMappingURL=common-pipeline-functions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-pipeline-functions.js","sourceRoot":"/","sources":["utilities/pipelines/common-pipeline-functions.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"common-pipeline-functions.js","sourceRoot":"/","sources":["utilities/pipelines/common-pipeline-functions.ts"],"names":[],"mappings":";;;AAQO,MAAM,yBAAyB,GAAG,CAAC,KAAU,EAAuB,EAAE;IAC5E,OAAO;QACN,KAAK,EAAE;YACN,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;YACtB;gBACC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;aAClB;YACD,CAAC;SACD;KACD,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,yBAAyB,6BAUpC;AAcK,MAAM,8BAA8B,GAAG,CAAC,KAAU,EAAuB,EAAE;IACjF,OAAO;QACN,KAAK,EAAE;YACN,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;YACtB;gBACC,SAAS,EAAE;oBACV;wBACC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;qBACvC;oBACD,IAAI;iBACJ;aACD;YACD,CAAC;SACD;KACD,CAAC;AACH,CAAC,CAAC;AAfW,QAAA,8BAA8B,kCAezC","sourcesContent":["/**\n * Rounds a base currency value to 2 decimal places inside an aggregation pipeline.\n *\n * ✅ Use when:\n * - You want to round a monetary value like USD, BDT, etc. to 2 decimals.\n *\n * Example: 123.456 → 123.46\n */\nexport const getRoundBaseCurrencyStage = (value: any): Record<string, any> => {\n\treturn {\n\t\t$cond: [\n\t\t\t{ $ne: [value, null] },\n\t\t\t{\n\t\t\t\t$round: [value, 2],\n\t\t\t},\n\t\t\t0,\n\t\t],\n\t};\n};\n\n/**\n * Rounds a numeric value to the nearest thousand (secondary currency rounding).\n *\n * ✅ Use when:\n * - You’re working with a secondary currency (e.g., large denomination or summary view)\n * - You want rounding like: 123456 → 123000\n *\n * 🧠 Logic:\n * - Divide by 1000\n * - Round to nearest integer\n * - Multiply back by 1000\n */\nexport const getRoundSecondaryCurrencyStage = (value: any): Record<string, any> => {\n\treturn {\n\t\t$cond: [\n\t\t\t{ $ne: [value, null] },\n\t\t\t{\n\t\t\t\t$multiply: [\n\t\t\t\t\t{\n\t\t\t\t\t\t$round: [{ $divide: [value, 1000] }, 0],\n\t\t\t\t\t},\n\t\t\t\t\t1000,\n\t\t\t\t],\n\t\t\t},\n\t\t\t0,\n\t\t],\n\t};\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { PipelineStage } from 'mongoose';
|
|
2
|
-
export declare function addProductMarketingInfo(exchangeRate: number,
|
|
3
|
-
export declare function addSecondaryCurrencyToPriceBreakdowns(exchangeRate: number
|
|
2
|
+
export declare function addProductMarketingInfo(exchangeRate: number, secondaryCurrencyName: string): PipelineStage[];
|
|
3
|
+
export declare function addSecondaryCurrencyToPriceBreakdowns(exchangeRate: number): PipelineStage;
|
|
4
4
|
export declare function addDiscountAmountsToPriceBreakdowns(): PipelineStage;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.addProductMarketingInfo = addProductMarketingInfo;
|
|
4
4
|
exports.addSecondaryCurrencyToPriceBreakdowns = addSecondaryCurrencyToPriceBreakdowns;
|
|
5
5
|
exports.addDiscountAmountsToPriceBreakdowns = addDiscountAmountsToPriceBreakdowns;
|
|
6
|
-
const common_pipeline_functions_1 = require("./common-pipeline-functions");
|
|
7
6
|
const enum_1 = require("../enum");
|
|
8
|
-
|
|
7
|
+
const common_pipeline_functions_1 = require("./common-pipeline-functions");
|
|
8
|
+
function addProductMarketingInfo(exchangeRate, secondaryCurrencyName) {
|
|
9
9
|
return [
|
|
10
10
|
{
|
|
11
11
|
$lookup: {
|
|
@@ -45,10 +45,8 @@ function addProductMarketingInfo(exchangeRate, secondaryCurrencyRoundTo, seconda
|
|
|
45
45
|
secondaryCurrencyValue: {
|
|
46
46
|
$cond: [
|
|
47
47
|
{ $eq: ['$valueType', 'fixed'] },
|
|
48
|
-
(0, common_pipeline_functions_1.
|
|
49
|
-
|
|
50
|
-
exchangeRate,
|
|
51
|
-
roundTo: secondaryCurrencyRoundTo,
|
|
48
|
+
(0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
49
|
+
$multiply: ['$value', exchangeRate],
|
|
52
50
|
}),
|
|
53
51
|
'$$REMOVE',
|
|
54
52
|
],
|
|
@@ -119,7 +117,7 @@ function addProductMarketingInfo(exchangeRate, secondaryCurrencyRoundTo, seconda
|
|
|
119
117
|
},
|
|
120
118
|
];
|
|
121
119
|
}
|
|
122
|
-
function addSecondaryCurrencyToPriceBreakdowns(exchangeRate
|
|
120
|
+
function addSecondaryCurrencyToPriceBreakdowns(exchangeRate) {
|
|
123
121
|
return {
|
|
124
122
|
$addFields: {
|
|
125
123
|
priceBreakdowns: {
|
|
@@ -130,18 +128,14 @@ function addSecondaryCurrencyToPriceBreakdowns(exchangeRate, secondaryCurrencyRo
|
|
|
130
128
|
$mergeObjects: [
|
|
131
129
|
'$$breakdown',
|
|
132
130
|
{
|
|
133
|
-
secondaryPrice: (0, common_pipeline_functions_1.
|
|
134
|
-
|
|
135
|
-
exchangeRate,
|
|
136
|
-
roundTo: secondaryCurrencyRoundTo,
|
|
131
|
+
secondaryPrice: (0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
132
|
+
$multiply: ['$$breakdown.price', exchangeRate],
|
|
137
133
|
}),
|
|
138
134
|
secondaryDiscountAmount: {
|
|
139
135
|
$cond: [
|
|
140
136
|
{ $gt: ['$productMarketing', null] },
|
|
141
|
-
(0, common_pipeline_functions_1.
|
|
142
|
-
|
|
143
|
-
exchangeRate,
|
|
144
|
-
roundTo: secondaryCurrencyRoundTo,
|
|
137
|
+
(0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
138
|
+
$multiply: ['$$breakdown.discountAmount', exchangeRate],
|
|
145
139
|
}),
|
|
146
140
|
'$$REMOVE',
|
|
147
141
|
],
|
|
@@ -149,10 +143,8 @@ function addSecondaryCurrencyToPriceBreakdowns(exchangeRate, secondaryCurrencyRo
|
|
|
149
143
|
secondaryDiscountedPrice: {
|
|
150
144
|
$cond: [
|
|
151
145
|
{ $gt: ['$productMarketing', null] },
|
|
152
|
-
(0, common_pipeline_functions_1.
|
|
153
|
-
|
|
154
|
-
exchangeRate,
|
|
155
|
-
roundTo: secondaryCurrencyRoundTo,
|
|
146
|
+
(0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
|
|
147
|
+
$multiply: ['$$breakdown.discountedPrice', exchangeRate],
|
|
156
148
|
}),
|
|
157
149
|
'$$REMOVE',
|
|
158
150
|
],
|
|
@@ -183,14 +175,14 @@ function addDiscountAmountsToPriceBreakdowns() {
|
|
|
183
175
|
$cond: [
|
|
184
176
|
{ $eq: ['$productMarketing.valueType', enum_1.ValueType.FIXED] },
|
|
185
177
|
'$productMarketing.value',
|
|
186
|
-
{
|
|
178
|
+
(0, common_pipeline_functions_1.getRoundBaseCurrencyStage)({
|
|
187
179
|
$multiply: [
|
|
188
|
-
'
|
|
180
|
+
'$$breakdown.price',
|
|
189
181
|
{
|
|
190
|
-
$divide: ['
|
|
182
|
+
$divide: ['$productMarketing.value', 100],
|
|
191
183
|
},
|
|
192
184
|
],
|
|
193
|
-
},
|
|
185
|
+
}),
|
|
194
186
|
],
|
|
195
187
|
},
|
|
196
188
|
'$$REMOVE',
|
|
@@ -199,25 +191,25 @@ function addDiscountAmountsToPriceBreakdowns() {
|
|
|
199
191
|
discountedPrice: {
|
|
200
192
|
$cond: [
|
|
201
193
|
{ $gt: ['$productMarketing', null] },
|
|
202
|
-
{
|
|
194
|
+
(0, common_pipeline_functions_1.getRoundBaseCurrencyStage)({
|
|
203
195
|
$subtract: [
|
|
204
196
|
'$$breakdown.price',
|
|
205
197
|
{
|
|
206
198
|
$cond: [
|
|
207
199
|
{ $eq: ['$productMarketing.valueType', enum_1.ValueType.FIXED] },
|
|
208
200
|
'$productMarketing.value',
|
|
209
|
-
{
|
|
201
|
+
(0, common_pipeline_functions_1.getRoundBaseCurrencyStage)({
|
|
210
202
|
$multiply: [
|
|
211
|
-
'
|
|
203
|
+
'$$breakdown.price',
|
|
212
204
|
{
|
|
213
|
-
$divide: ['
|
|
205
|
+
$divide: ['$productMarketing.value', 100],
|
|
214
206
|
},
|
|
215
207
|
],
|
|
216
|
-
},
|
|
208
|
+
}),
|
|
217
209
|
],
|
|
218
210
|
},
|
|
219
211
|
],
|
|
220
|
-
},
|
|
212
|
+
}),
|
|
221
213
|
'$$REMOVE',
|
|
222
214
|
],
|
|
223
215
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-pipeline-stages.js","sourceRoot":"/","sources":["utilities/pipelines/product-pipeline-stages.ts"],"names":[],"mappings":";;AAIA,0DAsHC;AAED,sFAgDC;AAED,kFAkEC;AA/OD,2EAAwE;AACxE,kCAAmD;AAEnD,SAAgB,uBAAuB,CACtC,YAAoB,EACpB,wBAAgC,EAChC,qBAA6B;IAE7B,OAAO;QACN;YACC,OAAO,EAAE;gBACR,IAAI,EAAE,mBAAmB;gBACzB,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE;gBAC3C,QAAQ,EAAE;oBACT;wBACC,M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EAAE;wCACN,EAAE,GAAG,EAAE,CAAC,mBAAmB,EAAE,IAAI,CAAC,EAAE;wCACpC;4CACC,SAAS,EAAE;gDACV,mBAAmB;gDACnB;oDACC,KAAK,EAAE;wDACN,EAAE,GAAG,EAAE,CAAC,6BAA6B,EAAE,gBAAS,CAAC,KAAK,CAAC,EAAE;wDACzD,yBAAyB;wDACzB;4DACC,SAAS,EAAE;gEACV,yBAAyB;gEACzB;oEACC,OAAO,EAAE,CAAC,mBAAmB,EAAE,GAAG,CAAC;iEACnC;6DACD;yDACD;qDACD;iDACD;6CACD;yCACD;wCACD,UAAU;qCACV;iCACD;6BACD;yBACD;qBACD;iBACD;aACD;SACD;KACD,CAAC;AACH,CAAC","sourcesContent":["import { PipelineStage } from 'mongoose';\nimport { getSecondaryCurrencyStage } from './common-pipeline-functions';\nimport { MarketingType, ValueType } from '../enum';\n\nexport function addProductMarketingInfo(\n\texchangeRate: number,\n\tsecondaryCurrencyRoundTo: number,\n\tsecondaryCurrencyName: string\n): PipelineStage[] {\n\treturn [\n\t\t{\n\t\t\t$lookup: {\n\t\t\t\tfrom: 'productMarketings',\n\t\t\t\tlet: { productId: '$_id', now: new Date() },\n\t\t\t\tpipeline: [\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: { $eq: ['$product', '$$productId'] },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$lookup: {\n\t\t\t\t\t\t\tfrom: 'marketings',\n\t\t\t\t\t\t\tlocalField: 'marketing',\n\t\t\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\t\t\tas: 'marketing',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$unwind: '$marketing',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.status', 'active'] },\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.pausedAt', null] },\n\t\t\t\t\t\t\t\t\t{ $lte: ['$marketing.duration.start', '$$now'] },\n\t\t\t\t\t\t\t\t\t{ $gte: ['$marketing.duration.end', '$$now'] },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t// Compute and add secondary currency values to coupon documents\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tsecondaryCurrencyValue: {\n\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$valueType', 'fixed'] },\n\t\t\t\t\t\t\t\t\tgetSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\tvaluePath: '$value',\n\t\t\t\t\t\t\t\t\t\texchangeRate,\n\t\t\t\t\t\t\t\t\t\troundTo: secondaryCurrencyRoundTo,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tlabel: {\n\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.BUY1GET1] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Buy 1 Get 1',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.PUNCH_MARKETING] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Punch',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.DISCOUNT] },\n\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsecondaryCurrencyName,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t' ',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $toString: '$secondaryCurrencyValue' },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.PERCENTAGE] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [{ $toString: '$value' }, '%'],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\tdefault: 'Discount',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\tdefault: '$marketing.marketingType',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$project: {\n\t\t\t\t\t\t\tmarketing: '$marketing._id',\n\t\t\t\t\t\t\tisBuy1Get1: '$isBuy1Get1',\n\t\t\t\t\t\t\tvalueType: '$valueType',\n\t\t\t\t\t\t\tvalue: '$value',\n\t\t\t\t\t\t\tsecondaryCurrencyValue: '$secondaryCurrencyValue',\n\t\t\t\t\t\t\tlabel: '$label',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tas: 'productMarketing',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\t$unwind: { path: '$productMarketing', preserveNullAndEmptyArrays: true },\n\t\t},\n\t];\n}\n\nexport function addSecondaryCurrencyToPriceBreakdowns(\n\texchangeRate: number,\n\tsecondaryCurrencyRoundTo: number\n): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tsecondaryPrice: getSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\tvaluePath: '$$breakdown.price',\n\t\t\t\t\t\t\t\t\texchangeRate,\n\t\t\t\t\t\t\t\t\troundTo: secondaryCurrencyRoundTo,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\tsecondaryDiscountAmount: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] },\n\t\t\t\t\t\t\t\t\t\tgetSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\tvaluePath: '$$breakdown.discountAmount',\n\t\t\t\t\t\t\t\t\t\t\texchangeRate,\n\t\t\t\t\t\t\t\t\t\t\troundTo: secondaryCurrencyRoundTo,\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsecondaryDiscountedPrice: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] },\n\t\t\t\t\t\t\t\t\t\tgetSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\tvaluePath: '$$breakdown.discountedPrice',\n\t\t\t\t\t\t\t\t\t\t\texchangeRate,\n\t\t\t\t\t\t\t\t\t\t\troundTo: secondaryCurrencyRoundTo,\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport function addDiscountAmountsToPriceBreakdowns(): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdiscountAmount: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\t// if valueType is fixed, use value directly\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t// if valueType is percentage, calculate percentage of price\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$$breakdown.price', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t// Add discounted price\n\t\t\t\t\t\t\t\tdiscountedPrice: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$subtract: [\n\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$$breakdown.price', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"product-pipeline-stages.js","sourceRoot":"/","sources":["utilities/pipelines/product-pipeline-stages.ts"],"names":[],"mappings":";;AAIA,0DAmHC;AAED,sFAwCC;AAED,kFAkEC;AApOD,kCAAmD;AACnD,2EAAwG;AAExG,SAAgB,uBAAuB,CACtC,YAAoB,EACpB,qBAA6B;IAE7B,OAAO;QACN;YACC,OAAO,EAAE;gBACR,IAAI,EAAE,mBAAmB;gBACzB,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE;gBAC3C,QAAQ,EAAE;oBACT;wBACC,MAAM,EAAE;4BACP,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,EAAE;yBAC3C;qBACD;oBACD;wBACC,OAAO,EAAE;4BACR,IAAI,EAAE,YAAY;4BAClB,UAAU,EAAE,WAAW;4BACvB,YAAY,EAAE,KAAK;4BACnB,EAAE,EAAE,WAAW;yBACf;qBACD;oBACD;wBACC,OAAO,EAAE,YAAY;qBACrB;oBACD;wBACC,MAAM,EAAE;4BACP,K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E,GAAG,CAAC;iEACzC;6DACD;yDACD,CAAC;qDACF;iDACD;6CACD;yCACD,CAAC;wCACF,UAAU;qCACV;iCACD;6BACD;yBACD;qBACD;iBACD;aACD;SACD;KACD,CAAC;AACH,CAAC","sourcesContent":["import { PipelineStage } from 'mongoose';\nimport { MarketingType, ValueType } from '../enum';\nimport { getRoundBaseCurrencyStage, getRoundSecondaryCurrencyStage } from './common-pipeline-functions';\n\nexport function addProductMarketingInfo(\n\texchangeRate: number,\n\tsecondaryCurrencyName: string\n): PipelineStage[] {\n\treturn [\n\t\t{\n\t\t\t$lookup: {\n\t\t\t\tfrom: 'productMarketings',\n\t\t\t\tlet: { productId: '$_id', now: new Date() },\n\t\t\t\tpipeline: [\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: { $eq: ['$product', '$$productId'] },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$lookup: {\n\t\t\t\t\t\t\tfrom: 'marketings',\n\t\t\t\t\t\t\tlocalField: 'marketing',\n\t\t\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\t\t\tas: 'marketing',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$unwind: '$marketing',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t$expr: {\n\t\t\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.status', 'active'] },\n\t\t\t\t\t\t\t\t\t{ $eq: ['$marketing.pausedAt', null] },\n\t\t\t\t\t\t\t\t\t{ $lte: ['$marketing.duration.start', '$$now'] },\n\t\t\t\t\t\t\t\t\t{ $gte: ['$marketing.duration.end', '$$now'] },\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t// Compute and add secondary currency values to coupon documents\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tsecondaryCurrencyValue: {\n\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t{ $eq: ['$valueType', 'fixed'] },\n\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t$multiply: ['$value', exchangeRate],\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$addFields: {\n\t\t\t\t\t\t\tlabel: {\n\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.BUY1GET1] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Buy 1 Get 1',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.PUNCH_MARKETING] },\n\t\t\t\t\t\t\t\t\t\t\tthen: 'Punch',\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$marketing.marketingType', MarketingType.DISCOUNT] },\n\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t$switch: {\n\t\t\t\t\t\t\t\t\t\t\t\t\tbranches: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsecondaryCurrencyName,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t' ',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $toString: '$secondaryCurrencyValue' },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcase: { $eq: ['$valueType', ValueType.PERCENTAGE] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthen: {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$concat: [{ $toString: '$value' }, '%'],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\tdefault: 'Discount',\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\tdefault: '$marketing.marketingType',\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$project: {\n\t\t\t\t\t\t\tmarketing: '$marketing._id',\n\t\t\t\t\t\t\tisBuy1Get1: '$isBuy1Get1',\n\t\t\t\t\t\t\tvalueType: '$valueType',\n\t\t\t\t\t\t\tvalue: '$value',\n\t\t\t\t\t\t\tsecondaryCurrencyValue: '$secondaryCurrencyValue',\n\t\t\t\t\t\t\tlabel: '$label',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tas: 'productMarketing',\n\t\t\t},\n\t\t},\n\t\t{\n\t\t\t$unwind: { path: '$productMarketing', preserveNullAndEmptyArrays: true },\n\t\t},\n\t];\n}\n\nexport function addSecondaryCurrencyToPriceBreakdowns(exchangeRate: number): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tsecondaryPrice: getRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t$multiply: ['$$breakdown.price', exchangeRate],\n\t\t\t\t\t\t\t\t}),\n\n\t\t\t\t\t\t\t\tsecondaryDiscountAmount: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] },\n\t\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t$multiply: ['$$breakdown.discountAmount', exchangeRate],\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tsecondaryDiscountedPrice: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] },\n\t\t\t\t\t\t\t\t\t\tgetRoundSecondaryCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t$multiply: ['$$breakdown.discountedPrice', exchangeRate],\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // Removes field if condition not met\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport function addDiscountAmountsToPriceBreakdowns(): PipelineStage {\n\treturn {\n\t\t$addFields: {\n\t\t\tpriceBreakdowns: {\n\t\t\t\t$map: {\n\t\t\t\t\tinput: '$priceBreakdowns',\n\t\t\t\t\tas: 'breakdown',\n\t\t\t\t\tin: {\n\t\t\t\t\t\t$mergeObjects: [\n\t\t\t\t\t\t\t'$$breakdown',\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdiscountAmount: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\t// if valueType is fixed, use value directly\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t// if valueType is percentage, calculate percentage of price\n\t\t\t\t\t\t\t\t\t\t\t\tgetRoundBaseCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$productMarketing.value', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t// Add discounted price\n\t\t\t\t\t\t\t\tdiscountedPrice: {\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t{ $gt: ['$productMarketing', null] }, // checks existence\n\t\t\t\t\t\t\t\t\t\tgetRoundBaseCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t$subtract: [\n\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{ $eq: ['$productMarketing.valueType', ValueType.FIXED] },\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$productMarketing.value',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tgetRoundBaseCurrencyStage({\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$multiply: [\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'$$breakdown.price',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$divide: ['$productMarketing.value', 100],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\t\t'$$REMOVE', // omit field if productMarketing is missing\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
export declare const BaseCurrencyRoundTo = 0.01;
|
|
2
|
+
export declare const SecondaryCurrencyRoundTo = 1000;
|
|
1
3
|
export declare const roundCurrencySync: (amount: number, roundingFactor: number) => number;
|
|
2
|
-
export declare const
|
|
4
|
+
export declare const roundBaseCurrency: (amount: number) => number;
|
|
5
|
+
export declare const roundSecondaryCurrency: (amount: number) => number;
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.roundSecondaryCurrency = exports.roundBaseCurrency = exports.roundCurrencySync = exports.SecondaryCurrencyRoundTo = exports.BaseCurrencyRoundTo = void 0;
|
|
4
|
+
exports.BaseCurrencyRoundTo = 0.01;
|
|
5
|
+
exports.SecondaryCurrencyRoundTo = 1000;
|
|
4
6
|
const roundCurrencySync = (amount, roundingFactor) => {
|
|
5
|
-
if (amount
|
|
7
|
+
if (typeof amount !== 'number' ||
|
|
8
|
+
isNaN(amount) ||
|
|
9
|
+
typeof roundingFactor !== 'number' ||
|
|
10
|
+
roundingFactor <= 0 ||
|
|
11
|
+
amount === 0) {
|
|
6
12
|
return 0;
|
|
7
|
-
|
|
13
|
+
}
|
|
8
14
|
const decimals = (roundingFactor.toString().split('.')[1] || '').length;
|
|
15
|
+
const rounded = Math.round(amount / roundingFactor) * roundingFactor;
|
|
9
16
|
return Number(rounded.toFixed(decimals));
|
|
10
17
|
};
|
|
11
18
|
exports.roundCurrencySync = roundCurrencySync;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (!roundTo)
|
|
19
|
-
return amount;
|
|
20
|
-
return (0, exports.roundCurrencySync)(amount, roundTo);
|
|
19
|
+
const roundBaseCurrency = (amount) => {
|
|
20
|
+
return (0, exports.roundCurrencySync)(amount, exports.BaseCurrencyRoundTo);
|
|
21
|
+
};
|
|
22
|
+
exports.roundBaseCurrency = roundBaseCurrency;
|
|
23
|
+
const roundSecondaryCurrency = (amount) => {
|
|
24
|
+
return (0, exports.roundCurrencySync)(amount, exports.SecondaryCurrencyRoundTo);
|
|
21
25
|
};
|
|
22
|
-
exports.
|
|
26
|
+
exports.roundSecondaryCurrency = roundSecondaryCurrency;
|
|
23
27
|
//# sourceMappingURL=currency.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/shared/currency.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/shared/currency.ts"],"names":[],"mappings":";;;AACa,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAC3B,QAAA,wBAAwB,GAAG,IAAI,CAAC;AAGtC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,cAAsB,EAAU,EAAE;IACnF,IACC,OAAO,MAAM,KAAK,QAAQ;QAC1B,KAAK,CAAC,MAAM,CAAC;QACb,OAAO,cAAc,KAAK,QAAQ;QAClC,cAAc,IAAI,CAAC;QACnB,MAAM,KAAK,CAAC,EACX,CAAC;QACF,OAAO,CAAC,CAAC;IACV,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACxE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,GAAG,cAAc,CAAC;IAErE,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC;AAfW,QAAA,iBAAiB,qBAe5B;AAGK,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAU,EAAE;IAC3D,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,2BAAmB,CAAC,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAU,EAAE;IAChE,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,gCAAwB,CAAC,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC","sourcesContent":["// === Currency Rounding Constants ===\nexport const BaseCurrencyRoundTo = 0.01;\nexport const SecondaryCurrencyRoundTo = 1000;\n\n// === Safely rounds a number to the nearest rounding unit ===\nexport const roundCurrencySync = (amount: number, roundingFactor: number): number => {\n\tif (\n\t\ttypeof amount !== 'number' ||\n\t\tisNaN(amount) ||\n\t\ttypeof roundingFactor !== 'number' ||\n\t\troundingFactor <= 0 ||\n\t\tamount === 0\n\t) {\n\t\treturn 0;\n\t}\n\n\tconst decimals = (roundingFactor.toString().split('.')[1] || '').length;\n\tconst rounded = Math.round(amount / roundingFactor) * roundingFactor;\n\n\treturn Number(rounded.toFixed(decimals));\n};\n\n// === Specific rounding functions for base and secondary currencies ===\nexport const roundBaseCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, BaseCurrencyRoundTo);\n};\n\nexport const roundSecondaryCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, SecondaryCurrencyRoundTo);\n};\n"]}
|