@hyper.software/common-helpers 2.10.40 → 2.10.41
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.
|
@@ -52,50 +52,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.calculateDynamicPricing = void 0;
|
|
54
54
|
var moment_1 = __importDefault(require("moment"));
|
|
55
|
-
var dateService_1 = require("../dateService/dateService");
|
|
56
55
|
var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
57
|
-
var basePriceMap, resultPricing,
|
|
58
|
-
var
|
|
56
|
+
var basePriceMap, resultPricing, affectedDates, _i, _c, holiday, date, _d, _e, dateStr, base, isAffected;
|
|
57
|
+
var _f;
|
|
59
58
|
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
60
|
-
return __generator(this, function (
|
|
59
|
+
return __generator(this, function (_g) {
|
|
61
60
|
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
62
61
|
resultPricing = {};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
68
|
-
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
69
|
-
]; }));
|
|
70
|
-
for (_i = 0, _c = Object.keys(currentPricing); _i < _c.length; _i++) {
|
|
71
|
-
dateStr = _c[_i];
|
|
72
|
-
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
73
|
-
if (!date.isValid())
|
|
62
|
+
affectedDates = new Set();
|
|
63
|
+
for (_i = 0, _c = company.holidays || []; _i < _c.length; _i++) {
|
|
64
|
+
holiday = _c[_i];
|
|
65
|
+
if (!holiday.enableDynamicPricing)
|
|
74
66
|
continue;
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
date = (0, moment_1.default)(holiday.date);
|
|
68
|
+
affectedDates.add(date.clone().subtract(1, 'day').format('YYYY-MM-DD'));
|
|
69
|
+
affectedDates.add(date.format('YYYY-MM-DD'));
|
|
70
|
+
affectedDates.add(date.clone().add(1, 'day').format('YYYY-MM-DD'));
|
|
71
|
+
}
|
|
72
|
+
for (_d = 0, _e = Object.keys(currentPricing); _d < _e.length; _d++) {
|
|
73
|
+
dateStr = _e[_d];
|
|
74
|
+
base = (_f = basePriceMap[dateStr]) !== null && _f !== void 0 ? _f : currentPricing[dateStr];
|
|
77
75
|
if (!(dateStr in basePriceMap)) {
|
|
78
76
|
basePriceMap[dateStr] = base;
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (dynamicPricing.amount) {
|
|
84
|
-
if (dynamicPricing.type === 'INCREASE') {
|
|
85
|
-
increasedPrice = baseForToday + dynamicPricing.amount;
|
|
86
|
-
}
|
|
87
|
-
else if (dynamicPricing.type === 'DECREASE') {
|
|
88
|
-
increasedPrice = Math.max(0, baseForToday - dynamicPricing.amount);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
increasedPrice = Math.round(baseForToday * 1.05);
|
|
93
|
-
}
|
|
94
|
-
resultPricing[dateStr] = increasedPrice;
|
|
78
|
+
isAffected = affectedDates.has(dateStr);
|
|
79
|
+
if (dynamicPricing.isActive && isAffected) {
|
|
80
|
+
resultPricing[dateStr] = Math.round(base * 1.2);
|
|
95
81
|
}
|
|
96
|
-
else {
|
|
82
|
+
else if (!dynamicPricing.isActive && base !== undefined) {
|
|
97
83
|
resultPricing[dateStr] = base;
|
|
98
84
|
}
|
|
85
|
+
else {
|
|
86
|
+
resultPricing[dateStr] = currentPricing[dateStr];
|
|
87
|
+
}
|
|
99
88
|
}
|
|
100
89
|
return [2 /*return*/, {
|
|
101
90
|
updatedPricing: resultPricing,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;
|
|
1
|
+
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAGpB,IAAM,uBAAuB,GAAG,iEAAO,EAU7C;;;QATC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA;;QAUD,YAAY,yBAAQ,cAAc,CAAC,SAAS,GAAK,oBAAoB,CAAE,CAAA;QACvE,aAAa,GAAyC,EAAE,CAAA;QAExD,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QAEvC,WAA4C,EAAtB,KAAA,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAtB,cAAsB,EAAtB,IAAsB,EAAE,CAAC;YAApC,OAAO;YAChB,IAAI,CAAC,OAAO,CAAC,oBAAoB;gBAAE,SAAQ;YAErC,IAAI,GAAG,IAAA,gBAAM,EAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YACjC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;YACvE,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;YAC5C,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;QACpE,CAAC;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