@lyxa.ai/core 1.0.68 → 1.0.69
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/embedded/currency.model.d.ts +1 -0
- package/dist/libraries/mongo/models/embedded/currency.model.js +5 -0
- package/dist/libraries/mongo/models/embedded/currency.model.js.map +1 -1
- package/dist/libraries/mongo/models/line-item.model.d.ts +8 -1
- package/dist/libraries/mongo/models/line-item.model.js +23 -0
- package/dist/libraries/mongo/models/line-item.model.js.map +1 -1
- package/dist/utilities/currency.d.ts +3 -0
- package/dist/utilities/currency.js +42 -0
- package/dist/utilities/currency.js.map +1 -0
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ class Currency {
|
|
|
15
15
|
symbol;
|
|
16
16
|
name;
|
|
17
17
|
code;
|
|
18
|
+
roundTo;
|
|
18
19
|
}
|
|
19
20
|
exports.Currency = Currency;
|
|
20
21
|
__decorate([
|
|
@@ -29,4 +30,8 @@ __decorate([
|
|
|
29
30
|
(0, typegoose_1.prop)({ type: String }),
|
|
30
31
|
__metadata("design:type", String)
|
|
31
32
|
], 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);
|
|
32
37
|
//# 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;IAGd,OAAO,CAAU;CACxB;AAZD,4BAYC;AAVO;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;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;yCACd","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\t@prop({ type: Number, default: 0.01 })\n\tpublic roundTo?: number;\n}\n"]}
|
|
@@ -3,12 +3,19 @@ import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
|
|
3
3
|
import { Cart } from './cart.model';
|
|
4
4
|
import { Product } from './product.model';
|
|
5
5
|
import { PriceBreakdown } from './embedded/price-breakdown.model';
|
|
6
|
-
import { PriceOption } from '../../../utilities/enum';
|
|
6
|
+
import { ItemType, PriceOption } from '../../../utilities/enum';
|
|
7
7
|
import { LineItemAttribute } from './embedded/line-item-attribute.model';
|
|
8
8
|
import { User } from './user.model';
|
|
9
|
+
import { Shop } from './shop.model';
|
|
10
|
+
import { Parent } from './parent.model';
|
|
11
|
+
import { Category } from './category.model';
|
|
9
12
|
export declare class LineItem extends TimeStamps {
|
|
10
13
|
cart: Ref<Cart>;
|
|
11
14
|
user: Ref<User>;
|
|
15
|
+
shop: Ref<Shop>;
|
|
16
|
+
parent: Ref<Parent>;
|
|
17
|
+
itemType: ItemType;
|
|
18
|
+
category: Ref<Category>;
|
|
12
19
|
product: Ref<Product>;
|
|
13
20
|
quantity?: number;
|
|
14
21
|
priceOption?: PriceOption;
|
|
@@ -18,9 +18,16 @@ const price_breakdown_model_1 = require("./embedded/price-breakdown.model");
|
|
|
18
18
|
const enum_1 = require("../../../utilities/enum");
|
|
19
19
|
const line_item_attribute_model_1 = require("./embedded/line-item-attribute.model");
|
|
20
20
|
const user_model_1 = require("./user.model");
|
|
21
|
+
const shop_model_1 = require("./shop.model");
|
|
22
|
+
const parent_model_1 = require("./parent.model");
|
|
23
|
+
const category_model_1 = require("./category.model");
|
|
21
24
|
let LineItem = class LineItem extends defaultClasses_1.TimeStamps {
|
|
22
25
|
cart;
|
|
23
26
|
user;
|
|
27
|
+
shop;
|
|
28
|
+
parent;
|
|
29
|
+
itemType;
|
|
30
|
+
category;
|
|
24
31
|
product;
|
|
25
32
|
quantity;
|
|
26
33
|
priceOption;
|
|
@@ -38,6 +45,22 @@ __decorate([
|
|
|
38
45
|
(0, typegoose_1.prop)({ required: true, ref: () => user_model_1.User }),
|
|
39
46
|
__metadata("design:type", Object)
|
|
40
47
|
], LineItem.prototype, "user", void 0);
|
|
48
|
+
__decorate([
|
|
49
|
+
(0, typegoose_1.prop)({ required: true, ref: () => shop_model_1.Shop }),
|
|
50
|
+
__metadata("design:type", Object)
|
|
51
|
+
], LineItem.prototype, "shop", void 0);
|
|
52
|
+
__decorate([
|
|
53
|
+
(0, typegoose_1.prop)({ required: true, ref: () => parent_model_1.Parent }),
|
|
54
|
+
__metadata("design:type", Object)
|
|
55
|
+
], LineItem.prototype, "parent", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
(0, typegoose_1.prop)({ required: true, type: String, enum: enum_1.ItemType }),
|
|
58
|
+
__metadata("design:type", String)
|
|
59
|
+
], LineItem.prototype, "itemType", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, typegoose_1.prop)({ required: true, ref: () => category_model_1.Category }),
|
|
62
|
+
__metadata("design:type", Object)
|
|
63
|
+
], LineItem.prototype, "category", void 0);
|
|
41
64
|
__decorate([
|
|
42
65
|
(0, typegoose_1.prop)({ required: true, ref: () => product_model_1.Product }),
|
|
43
66
|
__metadata("design:type", Object)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"line-item.model.js","sourceRoot":"/","sources":["libraries/mongo/models/line-item.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAgF;AAChF,4EAAqE;AACrE,6CAAoC;AACpC,mDAA0C;AAC1C,4EAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"line-item.model.js","sourceRoot":"/","sources":["libraries/mongo/models/line-item.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAgF;AAChF,4EAAqE;AACrE,6CAAoC;AACpC,mDAA0C;AAC1C,4EAAkE;AAClE,kDAAgE;AAChE,oFAAyE;AACzE,6CAAoC;AACpC,6CAAoC;AACpC,iDAAwC;AACxC,qDAA4C;AAkBrC,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,2BAAU;IAEhC,IAAI,CAAa;IAGjB,IAAI,CAAa;IAGjB,IAAI,CAAa;IAGjB,MAAM,CAAc;IAGpB,QAAQ,CAAY;IAGpB,QAAQ,CAAiB;IAGzB,OAAO,CAAgB;IAGvB,QAAQ,CAAU;IAGlB,WAAW,CAAe;IAG1B,cAAc,CAAiB;IAG/B,UAAU,CAAuB;IAGjC,kBAAkB,CAAY;IAG9B,mBAAmB,CAAU;CACpC,CAAA;AAvCY,4BAAQ;AAEb;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;sCAClB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;sCAClB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,QA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,QAAQ;IAbpB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE;YACd,UAAU,EAAE,WAAW;YACvB,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,IAAI,EAAE,CAAC,EAAE,CAAC;IAC3B,IAAA,iBAAK,EAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;GACT,QAAQ,CAuCpB","sourcesContent":["import { prop, Ref, index, modelOptions, Severity } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { Cart } from './cart.model';\nimport { Product } from './product.model';\nimport { PriceBreakdown } from './embedded/price-breakdown.model';\nimport { ItemType, PriceOption } from '../../../utilities/enum';\nimport { LineItemAttribute } from './embedded/line-item-attribute.model';\nimport { User } from './user.model';\nimport { Shop } from './shop.model';\nimport { Parent } from './parent.model';\nimport { Category } from './category.model';\n\n/**\n * LineItem model - Represents individual items in a cart\n */\n@modelOptions({\n\tschemaOptions: {\n\t\tcollection: 'lineItems',\n\t\ttoJSON: { virtuals: true },\n\t\ttoObject: { virtuals: true },\n\t},\n\toptions: {\n\t\tallowMixed: Severity.ALLOW,\n\t},\n})\n@index({ cart: 1 })\n@index({ cart: 1, user: 1 })\n@index({ product: 1 })\nexport class LineItem extends TimeStamps {\n\t@prop({ required: true, ref: () => Cart })\n\tpublic cart!: Ref<Cart>;\n\n\t@prop({ required: true, ref: () => User })\n\tpublic user!: Ref<User>;\n\n\t@prop({ required: true, ref: () => Shop })\n\tpublic shop!: Ref<Shop>;\n\n\t@prop({ required: true, ref: () => Parent })\n\tpublic parent: Ref<Parent>;\n\n\t@prop({ required: true, type: String, enum: ItemType })\n\tpublic itemType!: ItemType;\n\n\t@prop({ required: true, ref: () => Category })\n\tpublic category!: Ref<Category>;\n\n\t@prop({ required: true, ref: () => Product })\n\tpublic product!: Ref<Product>;\n\n\t@prop({ min: 1, default: 1 })\n\tpublic quantity?: number;\n\n\t@prop({ type: String, enum: PriceOption, default: PriceOption.SINGLE_PRICE })\n\tpublic priceOption?: PriceOption;\n\n\t@prop({ required: true, type: PriceBreakdown })\n\tpublic priceBreakdown: PriceBreakdown;\n\n\t@prop({ type: () => [LineItemAttribute], default: [] })\n\tpublic attributes?: LineItemAttribute[];\n\n\t@prop({ type: () => [String], default: [] })\n\tpublic removedIngredients?: string[];\n\n\t@prop()\n\tpublic specialInstructions?: string;\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToSecondary = exports.roundCurrency = void 0;
|
|
4
|
+
const settings_1 = require("../libraries/cache/settings");
|
|
5
|
+
const enum_1 = require("./enum");
|
|
6
|
+
const DEFAULT_ROUNDING_FACTOR = 0.01;
|
|
7
|
+
const DEFAULT_EXCHANGE_RATE = 1;
|
|
8
|
+
const getRoundingFactor = async (currency) => {
|
|
9
|
+
const settings = (await settings_1.cachedSettingsService.getSettings());
|
|
10
|
+
const currencySetting = settings.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
|
+
const getExchangeRate = async () => {
|
|
28
|
+
const settings = (await settings_1.cachedSettingsService.getSettings());
|
|
29
|
+
const currencySetting = settings.currencySetting;
|
|
30
|
+
return currencySetting?.exchangeRate || DEFAULT_EXCHANGE_RATE;
|
|
31
|
+
};
|
|
32
|
+
const roundCurrency = async (amount, currency) => {
|
|
33
|
+
const roundingFactor = await getRoundingFactor(currency);
|
|
34
|
+
return Math.round(amount / roundingFactor) * roundingFactor;
|
|
35
|
+
};
|
|
36
|
+
exports.roundCurrency = roundCurrency;
|
|
37
|
+
const convertToSecondary = async (amount) => {
|
|
38
|
+
const exchageRate = await getExchangeRate();
|
|
39
|
+
return (0, exports.roundCurrency)(amount * exchageRate, enum_1.PaidCurrency.SECONDARY);
|
|
40
|
+
};
|
|
41
|
+
exports.convertToSecondary = convertToSecondary;
|
|
42
|
+
//# sourceMappingURL=currency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/currency.ts"],"names":[],"mappings":";;;AAAA,0DAAoE;AAEpE,iCAAsC;AAEtC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC,MAAM,iBAAiB,GAAG,KAAK,EAAE,QAAsB,EAAmB,EAAE;IAC3E,MAAM,QAAQ,GAAG,CAAC,MAAM,gCAAqB,CAAC,WAAW,EAAE,CAAY,CAAC;IACxE,MAAM,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;IACjD,IAAI,cAAkC,CAAC;IACvC,IAAI,eAAe,EAAE,CAAC;QACrB,QAAQ,QAAQ,EAAE,CAAC;YAClB,KAAK,mBAAY,CAAC,IAAI;gBACrB,cAAc,GAAG,eAAe,CAAC,YAAY,EAAE,OAAO,CAAC;gBACvD,MAAM;YACP,KAAK,mBAAY,CAAC,SAAS;gBAC1B,cAAc,GAAG,eAAe,CAAC,iBAAiB,EAAE,OAAO,CAAC;gBAC5D,MAAM;YACP;gBACC,cAAc,GAAG,uBAAuB,CAAC;gBACzC,MAAM;QACR,CAAC;IACF,CAAC;IACD,OAAO,cAAc,IAAI,uBAAuB,CAAC;AAClD,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,KAAK,IAAqB,EAAE;IACnD,MAAM,QAAQ,GAAG,CAAC,MAAM,gCAAqB,CAAC,WAAW,EAAE,CAAY,CAAC;IACxE,MAAM,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;IACjD,OAAO,eAAe,EAAE,YAAY,IAAI,qBAAqB,CAAC;AAC/D,CAAC,CAAC;AAEK,MAAM,aAAa,GAAG,KAAK,EAAE,MAAc,EAAE,QAAsB,EAAmB,EAAE;IAC9F,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IACzD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,GAAG,cAAc,CAAC;AAC7D,CAAC,CAAC;AAHW,QAAA,aAAa,iBAGxB;AAEK,MAAM,kBAAkB,GAAG,KAAK,EAAE,MAAc,EAAmB,EAAE;IAC3E,MAAM,WAAW,GAAG,MAAM,eAAe,EAAE,CAAC;IAC5C,OAAO,IAAA,qBAAa,EAAC,MAAM,GAAG,WAAW,EAAE,mBAAY,CAAC,SAAS,CAAC,CAAC;AACpE,CAAC,CAAC;AAHW,QAAA,kBAAkB,sBAG7B","sourcesContent":["import { cachedSettingsService } from '../libraries/cache/settings';\nimport { Setting } from '../libraries/mongo/models';\nimport { PaidCurrency } from './enum';\n\nconst DEFAULT_ROUNDING_FACTOR = 0.01;\nconst DEFAULT_EXCHANGE_RATE = 1;\n\nconst getRoundingFactor = async (currency: PaidCurrency): Promise<number> => {\n\tconst settings = (await cachedSettingsService.getSettings()) as Setting;\n\tconst currencySetting = settings.currencySetting;\n\tlet roundingFactor: number | undefined;\n\tif (currencySetting) {\n\t\tswitch (currency) {\n\t\t\tcase PaidCurrency.BASE:\n\t\t\t\troundingFactor = currencySetting.baseCurrency?.roundTo;\n\t\t\t\tbreak;\n\t\t\tcase PaidCurrency.SECONDARY:\n\t\t\t\troundingFactor = currencySetting.secondaryCurrency?.roundTo;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\troundingFactor = DEFAULT_ROUNDING_FACTOR;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\treturn roundingFactor || DEFAULT_ROUNDING_FACTOR;\n};\n\nconst getExchangeRate = async (): Promise<number> => {\n\tconst settings = (await cachedSettingsService.getSettings()) as Setting;\n\tconst currencySetting = settings.currencySetting;\n\treturn currencySetting?.exchangeRate || DEFAULT_EXCHANGE_RATE;\n};\n\nexport const roundCurrency = async (amount: number, currency: PaidCurrency): Promise<number> => {\n\tconst roundingFactor = await getRoundingFactor(currency);\n\treturn Math.round(amount / roundingFactor) * roundingFactor;\n};\n\nexport const convertToSecondary = async (amount: number): Promise<number> => {\n\tconst exchageRate = await getExchangeRate();\n\treturn roundCurrency(amount * exchageRate, PaidCurrency.SECONDARY);\n};\n"]}
|