@hyper.software/common-helpers 2.10.33 → 2.10.35
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.
|
@@ -8,6 +8,4 @@ export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing,
|
|
|
8
8
|
updatedPricing: IRoomTypePricePlanPricingInformation;
|
|
9
9
|
updatedBasePriceMap: Record<string, number>;
|
|
10
10
|
}>;
|
|
11
|
-
export declare const
|
|
12
|
-
isNearFuture: boolean;
|
|
13
|
-
}) => number;
|
|
11
|
+
export declare const getSimpleDynamicMultiplier: (isNearFuture: boolean) => number;
|
|
@@ -50,32 +50,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.
|
|
53
|
+
exports.getSimpleDynamicMultiplier = 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 basePriceMap, resultPricing, period,
|
|
57
|
+
var basePriceMap, resultPricing, period, holidayDateSet, today, _i, period_1, dateStr, date, current, base, isAffectedHoliday, leadTimeDays, isNearFuture, baseForToday, leadTimeMultiplier, rawPrice, cappedPrice;
|
|
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
61
|
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
62
62
|
resultPricing = {};
|
|
63
63
|
period = Object.keys(currentPricing);
|
|
64
|
-
start = (0, moment_1.default)(dynamicPricing.startDate);
|
|
65
|
-
end = (0, moment_1.default)(dynamicPricing.endDate);
|
|
66
|
-
today = (0, moment_1.default)();
|
|
67
64
|
holidayDateSet = new Set((company.holidays || [])
|
|
68
|
-
.filter(function (h) {
|
|
69
|
-
var holidayMoment = (0, moment_1.default)(h.date);
|
|
70
|
-
return (h.enableDynamicPricing &&
|
|
71
|
-
holidayMoment.isSameOrAfter(start.clone().subtract(1, 'day')) &&
|
|
72
|
-
holidayMoment.isSameOrBefore(end.clone().add(1, 'day')));
|
|
73
|
-
})
|
|
65
|
+
.filter(function (h) { return h.enableDynamicPricing; })
|
|
74
66
|
.flatMap(function (h) { return [
|
|
75
67
|
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
76
68
|
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
77
69
|
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
78
70
|
]; }));
|
|
71
|
+
today = (0, moment_1.default)();
|
|
79
72
|
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
80
73
|
dateStr = period_1[_i];
|
|
81
74
|
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
@@ -83,26 +76,24 @@ var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], voi
|
|
|
83
76
|
continue;
|
|
84
77
|
current = currentPricing[dateStr];
|
|
85
78
|
base = (_c = basePriceMap[dateStr]) !== null && _c !== void 0 ? _c : current;
|
|
79
|
+
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
86
80
|
leadTimeDays = date.diff(today, 'days');
|
|
87
|
-
isNearHoliday = leadTimeDays <= 7;
|
|
88
81
|
isNearFuture = leadTimeDays < 30;
|
|
89
|
-
isAffectedHoliday
|
|
90
|
-
if (isAffectedHoliday) {
|
|
82
|
+
if (isAffectedHoliday && dynamicPricing.isActive) {
|
|
91
83
|
if (!(dateStr in basePriceMap)) {
|
|
92
84
|
basePriceMap[dateStr] = base;
|
|
93
85
|
}
|
|
86
|
+
baseForToday = basePriceMap[dateStr];
|
|
94
87
|
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
95
|
-
rawPrice =
|
|
96
|
-
cappedPrice =
|
|
88
|
+
rawPrice = baseForToday * (0, exports.getSimpleDynamicMultiplier)(isNearFuture) * leadTimeMultiplier;
|
|
89
|
+
cappedPrice = Math.min(rawPrice, baseForToday * 1.45);
|
|
97
90
|
resultPricing[dateStr] = Math.round(cappedPrice);
|
|
98
91
|
}
|
|
99
|
-
else if (!dynamicPricing.isActive &&
|
|
100
|
-
resultPricing[dateStr] =
|
|
92
|
+
else if (!dynamicPricing.isActive && dateStr in basePriceMap) {
|
|
93
|
+
resultPricing[dateStr] = basePriceMap[dateStr];
|
|
101
94
|
}
|
|
102
95
|
else {
|
|
103
|
-
|
|
104
|
-
resultPricing[dateStr] =
|
|
105
|
-
current === expected || current === Math.round((base !== null && base !== void 0 ? base : 0) * 1.2) ? (base !== null && base !== void 0 ? base : current) : current;
|
|
96
|
+
resultPricing[dateStr] = current;
|
|
106
97
|
}
|
|
107
98
|
}
|
|
108
99
|
return [2 /*return*/, {
|
|
@@ -112,9 +103,8 @@ var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], voi
|
|
|
112
103
|
});
|
|
113
104
|
}); };
|
|
114
105
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
115
|
-
var
|
|
116
|
-
|
|
117
|
-
return isNearFuture ? 1.1 : 1.0;
|
|
106
|
+
var getSimpleDynamicMultiplier = function (isNearFuture) {
|
|
107
|
+
return isNearFuture ? 1.2 : 1.1;
|
|
118
108
|
};
|
|
119
|
-
exports.
|
|
109
|
+
exports.getSimpleDynamicMultiplier = getSimpleDynamicMultiplier;
|
|
120
110
|
//# sourceMappingURL=dynamicPricingService.js.map
|
|
@@ -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,YAAY,yBAAQ,cAAc,CAAC,SAAS,GAAK,oBAAoB,CAAE,CAAA;QACvE,aAAa,GAAyC,EAAE,CAAA;QAExD,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;
|
|
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,YAAY,yBAAQ,cAAc,CAAC,SAAS,GAAK,oBAAoB,CAAE,CAAA;QACvE,aAAa,GAAyC,EAAE,CAAA;QAExD,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAEpC,cAAc,GAAG,IAAI,GAAG,CAC5B,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;aACrB,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,oBAAoB,EAAtB,CAAsB,CAAC;aACrC,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA;YACd,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;YACtD,IAAA,gBAAM,EAAC,CAAC,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