@hyper.software/common-helpers 2.2.81 → 2.2.83
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.
|
@@ -54,14 +54,14 @@ exports.calculateDynamicPricing = void 0;
|
|
|
54
54
|
var moment_1 = __importDefault(require("moment"));
|
|
55
55
|
var dateService_1 = require("../dateService/dateService");
|
|
56
56
|
var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
57
|
-
var
|
|
57
|
+
var resultPricing, basePriceMap, period, affectedDatesSet, _i, period_1, dateStr, isAffected, current, date, base, increase, rawPrice;
|
|
58
58
|
var _c;
|
|
59
59
|
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
60
60
|
return __generator(this, function (_d) {
|
|
61
|
-
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
62
61
|
resultPricing = {};
|
|
62
|
+
basePriceMap = __assign({}, existingBasePriceMap);
|
|
63
63
|
period = Object.keys(currentPricing);
|
|
64
|
-
|
|
64
|
+
affectedDatesSet = new Set((company.holidays || [])
|
|
65
65
|
.filter(function (h) { return h.enableDynamicPricing; })
|
|
66
66
|
.flatMap(function (h) { return [
|
|
67
67
|
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
@@ -76,22 +76,24 @@ var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], voi
|
|
|
76
76
|
}
|
|
77
77
|
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
78
78
|
dateStr = period_1[_i];
|
|
79
|
+
isAffected = affectedDatesSet.has(dateStr);
|
|
80
|
+
current = currentPricing[dateStr];
|
|
79
81
|
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
80
|
-
if (!date.isValid())
|
|
82
|
+
if (!isAffected || !date.isValid()) {
|
|
83
|
+
resultPricing[dateStr] = current;
|
|
81
84
|
continue;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (isAffectedHoliday && !(dateStr in basePriceMap) && typeof current === 'number') {
|
|
85
|
+
}
|
|
86
|
+
if (!(dateStr in basePriceMap) && typeof current === 'number') {
|
|
85
87
|
basePriceMap[dateStr] = current;
|
|
86
88
|
}
|
|
87
|
-
|
|
88
|
-
if (
|
|
89
|
-
resultPricing[dateStr] =
|
|
89
|
+
base = basePriceMap[dateStr];
|
|
90
|
+
if (base == null) {
|
|
91
|
+
resultPricing[dateStr] = current;
|
|
90
92
|
continue;
|
|
91
93
|
}
|
|
92
|
-
increase = (_c = dynamicPricing.amount) !== null && _c !== void 0 ? _c : Math.round(
|
|
94
|
+
increase = (_c = dynamicPricing.amount) !== null && _c !== void 0 ? _c : Math.round(base * 0.05);
|
|
93
95
|
increase += 10;
|
|
94
|
-
rawPrice = Math.min(
|
|
96
|
+
rawPrice = Math.min(base + increase, base + 70);
|
|
95
97
|
resultPricing[dateStr] = Math.round(rawPrice);
|
|
96
98
|
}
|
|
97
99
|
return [2 /*return*/, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAE3B,0DAA0D;AAEnD,IAAM,uBAAuB,GAAG,iEAAO,EAU7C;;;QATC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA;;QAUD,
|
|
1
|
+
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAE3B,0DAA0D;AAEnD,IAAM,uBA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