@hyper.software/common-helpers 2.2.62 → 2.2.64
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.
|
@@ -16,7 +16,3 @@ export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing,
|
|
|
16
16
|
updatedPricing: IRoomTypePricePlanPricingInformation;
|
|
17
17
|
updatedBasePriceMap: Record<string, number>;
|
|
18
18
|
}>;
|
|
19
|
-
export declare const getDynamicMultiplier: ({ availabilityRatio, isNearFuture, }: {
|
|
20
|
-
availabilityRatio: number;
|
|
21
|
-
isNearFuture: boolean;
|
|
22
|
-
}) => number;
|
|
@@ -50,76 +50,48 @@ 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.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,
|
|
58
|
-
var _f, _g, _h, _j, _k;
|
|
57
|
+
var basePriceMap, resultPricing, period, holidayDateSet, _i, period_1, dateStr, date, current, baseForToday, isAffectedHoliday, rawPrice;
|
|
59
58
|
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company, roomTypeId = _b.roomTypeId, companyId = _b.companyId, getRoomTypesAvailability = _b.getRoomTypesAvailability, getRoomsByCompanyId = _b.getRoomsByCompanyId;
|
|
60
|
-
return __generator(this, function (
|
|
61
|
-
switch (
|
|
59
|
+
return __generator(this, function (_c) {
|
|
60
|
+
switch (_c.label) {
|
|
62
61
|
case 0:
|
|
63
62
|
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
64
63
|
resultPricing = {};
|
|
65
64
|
period = Object.keys(currentPricing);
|
|
66
|
-
return [4 /*yield*/, Promise.all([
|
|
67
|
-
getRoomTypesAvailability(companyId, [roomTypeId], { period: period }),
|
|
68
|
-
getRoomsByCompanyId(companyId),
|
|
69
|
-
])];
|
|
65
|
+
return [4 /*yield*/, Promise.all([getRoomTypesAvailability(companyId, [roomTypeId], { period: period }), getRoomsByCompanyId(companyId)])];
|
|
70
66
|
case 1:
|
|
71
|
-
_c
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
holidayDateSet.add(date.clone().add(1, 'day').format('YYYY-MM-DD'));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
today = (0, moment_1.default)();
|
|
85
|
-
for (_e = 0, period_1 = period; _e < period_1.length; _e++) {
|
|
86
|
-
dateStr = period_1[_e];
|
|
67
|
+
_c.sent();
|
|
68
|
+
holidayDateSet = new Set((company.holidays || [])
|
|
69
|
+
.filter(function (h) { return h.enableDynamicPricing; })
|
|
70
|
+
.flatMap(function (h) { return [
|
|
71
|
+
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
72
|
+
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
73
|
+
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
74
|
+
]; }));
|
|
75
|
+
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
76
|
+
dateStr = period_1[_i];
|
|
87
77
|
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
88
78
|
if (!date.isValid())
|
|
89
79
|
continue;
|
|
90
80
|
current = currentPricing[dateStr];
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (userOverrodePrice) {
|
|
94
|
-
resultPricing[dateStr] = current;
|
|
95
|
-
continue;
|
|
81
|
+
if (!(dateStr in basePriceMap)) {
|
|
82
|
+
basePriceMap[dateStr] = current;
|
|
96
83
|
}
|
|
97
|
-
|
|
98
|
-
resultPricing[dateStr] = current;
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
availableRooms = (_k = roomTypeAvailability[dateStr]) !== null && _k !== void 0 ? _k : 0;
|
|
102
|
-
availabilityRatio = availableRooms / totalRooms;
|
|
103
|
-
leadTimeDays = date.diff(today, 'days');
|
|
104
|
-
isNearHoliday = leadTimeDays <= 7;
|
|
105
|
-
isNearFuture = leadTimeDays < 30;
|
|
84
|
+
baseForToday = basePriceMap[dateStr];
|
|
106
85
|
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
86
|
+
if (dynamicPricing.isActive && isAffectedHoliday) {
|
|
87
|
+
rawPrice = baseForToday + (dynamicPricing.amount || Math.round(baseForToday * 0.05));
|
|
88
|
+
if (rawPrice > baseForToday + 70) {
|
|
89
|
+
rawPrice = baseForToday + 70;
|
|
111
90
|
}
|
|
112
|
-
|
|
113
|
-
occupancyMultiplier = (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture });
|
|
114
|
-
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
115
|
-
rawPrice = baseForToday * occupancyMultiplier * leadTimeMultiplier;
|
|
116
|
-
cappedPrice = isNearHoliday && availableRooms <= 1
|
|
117
|
-
? Math.min(rawPrice, baseForToday + 70)
|
|
118
|
-
: Math.min(rawPrice, baseForToday * 1.45);
|
|
119
|
-
resultPricing[dateStr] = Math.round(cappedPrice);
|
|
91
|
+
resultPricing[dateStr] = Math.round(rawPrice);
|
|
120
92
|
}
|
|
121
93
|
else {
|
|
122
|
-
resultPricing[dateStr] =
|
|
94
|
+
resultPricing[dateStr] = baseForToday;
|
|
123
95
|
}
|
|
124
96
|
}
|
|
125
97
|
return [2 /*return*/, {
|
|
@@ -130,15 +102,4 @@ var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], voi
|
|
|
130
102
|
});
|
|
131
103
|
}); };
|
|
132
104
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
133
|
-
var getDynamicMultiplier = function (_a) {
|
|
134
|
-
var availabilityRatio = _a.availabilityRatio, isNearFuture = _a.isNearFuture;
|
|
135
|
-
if (availabilityRatio <= 0.02)
|
|
136
|
-
return isNearFuture ? 1.5 : 1.4;
|
|
137
|
-
if (availabilityRatio <= 0.5)
|
|
138
|
-
return isNearFuture ? 1.4 : 1.2;
|
|
139
|
-
if (availabilityRatio < 1)
|
|
140
|
-
return isNearFuture ? 1.2 : 1.05;
|
|
141
|
-
return isNearFuture ? 1.1 : 1.0;
|
|
142
|
-
};
|
|
143
|
-
exports.getDynamicMultiplier = getDynamicMultiplier;
|
|
144
105
|
//# 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,EAkB7C
|
|
1
|
+
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAE3B,0DAA0D;AAEnD,IAAM,uBAAuB,GAAG,iEAAO,EAkB7C;;QAjBC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA,EACP,UAAU,gBAAA,EACV,SAAS,e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