@hyper.software/common-helpers 2.10.27 → 2.10.29
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,68 +50,58 @@ 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
|
|
58
|
-
var _d, _e, _f, _g, _h;
|
|
57
|
+
var period, enabledHolidays, affectedSet, affectedDates, basePriceMap, _i, period_1, d, resultPricing, _c, period_2, dateStr, date, 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 (_d) {
|
|
60
|
+
switch (_d.label) {
|
|
62
61
|
case 0:
|
|
63
|
-
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
64
|
-
resultPricing = {};
|
|
65
62
|
period = Object.keys(currentPricing);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
getRoomsByCompanyId(companyId),
|
|
69
|
-
])];
|
|
70
|
-
case 1:
|
|
71
|
-
_c = _j.sent(), roomTypesAvailability = _c[0], roomsData = _c[1];
|
|
72
|
-
roomTypeAvailability = (_e = (_d = roomTypesAvailability === null || roomTypesAvailability === void 0 ? void 0 : roomTypesAvailability[roomTypeId]) === null || _d === void 0 ? void 0 : _d.availability) !== null && _e !== void 0 ? _e : {};
|
|
73
|
-
totalRooms = ((_f = roomsData === null || roomsData === void 0 ? void 0 : roomsData.list) === null || _f === void 0 ? void 0 : _f.filter(function (r) { return (r === null || r === void 0 ? void 0 : r.roomTypeId) === roomTypeId; }).length) || 1;
|
|
74
|
-
holidayDateSet = new Set((company.holidays || [])
|
|
75
|
-
.filter(function (h) { return h.enableDynamicPricing; })
|
|
76
|
-
.flatMap(function (h) { return [
|
|
63
|
+
enabledHolidays = (company.holidays || []).filter(function (h) { return h.enableDynamicPricing; });
|
|
64
|
+
affectedSet = new Set(enabledHolidays.flatMap(function (h) { return [
|
|
77
65
|
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
78
66
|
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
79
67
|
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
80
68
|
]; }));
|
|
81
|
-
|
|
69
|
+
affectedDates = period.filter(function (d) { return affectedSet.has(d); });
|
|
70
|
+
basePriceMap = __assign(__assign({}, (dynamicPricing.basePrice || {})), existingBasePriceMap);
|
|
82
71
|
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
83
|
-
|
|
72
|
+
d = period_1[_i];
|
|
73
|
+
if (!(d in basePriceMap)) {
|
|
74
|
+
basePriceMap[d] = currentPricing[d];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (!(dynamicPricing === null || dynamicPricing === void 0 ? void 0 : dynamicPricing.isActive) || affectedDates.length === 0) {
|
|
78
|
+
return [2 /*return*/, {
|
|
79
|
+
updatedPricing: __assign({}, currentPricing),
|
|
80
|
+
updatedBasePriceMap: basePriceMap,
|
|
81
|
+
}];
|
|
82
|
+
}
|
|
83
|
+
return [4 /*yield*/, Promise.all([
|
|
84
|
+
getRoomTypesAvailability(companyId, [roomTypeId], { period: affectedDates }),
|
|
85
|
+
getRoomsByCompanyId(companyId),
|
|
86
|
+
])];
|
|
87
|
+
case 1:
|
|
88
|
+
_d.sent();
|
|
89
|
+
resultPricing = {};
|
|
90
|
+
for (_c = 0, period_2 = period; _c < period_2.length; _c++) {
|
|
91
|
+
dateStr = period_2[_c];
|
|
84
92
|
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
85
93
|
if (!date.isValid())
|
|
86
94
|
continue;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
availableRooms = (_h = roomTypeAvailability[dateStr]) !== null && _h !== void 0 ? _h : 0;
|
|
90
|
-
availabilityRatio = availableRooms / totalRooms;
|
|
91
|
-
leadTimeDays = date.diff(today, 'days');
|
|
92
|
-
isNearHoliday = leadTimeDays <= 7;
|
|
93
|
-
isNearFuture = leadTimeDays < 30;
|
|
94
|
-
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
95
|
+
baseForToday = basePriceMap[dateStr];
|
|
96
|
+
isAffectedHoliday = affectedSet.has(dateStr);
|
|
95
97
|
if (isAffectedHoliday) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
occupancyMultiplier = (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture });
|
|
101
|
-
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
102
|
-
rawPrice = baseForToday * occupancyMultiplier * leadTimeMultiplier;
|
|
103
|
-
cappedPrice = isNearHoliday && availableRooms <= 1
|
|
104
|
-
? Math.min(rawPrice, baseForToday + 70)
|
|
105
|
-
: Math.min(rawPrice, baseForToday * 1.45);
|
|
106
|
-
resultPricing[dateStr] = Math.round(cappedPrice);
|
|
107
|
-
}
|
|
108
|
-
else if (!dynamicPricing.isActive && base !== undefined) {
|
|
109
|
-
resultPricing[dateStr] = base;
|
|
98
|
+
rawPrice = baseForToday + (dynamicPricing.amount || Math.round(baseForToday * 0.05));
|
|
99
|
+
if (rawPrice > baseForToday + 70)
|
|
100
|
+
rawPrice = baseForToday + 70;
|
|
101
|
+
resultPricing[dateStr] = Math.round(rawPrice);
|
|
110
102
|
}
|
|
111
103
|
else {
|
|
112
|
-
|
|
113
|
-
resultPricing[dateStr] =
|
|
114
|
-
current === expected || current === Math.round((base !== null && base !== void 0 ? base : 0) * 1.2) ? (base !== null && base !== void 0 ? base : current) : current;
|
|
104
|
+
resultPricing[dateStr] = baseForToday;
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
107
|
return [2 /*return*/, {
|
|
@@ -122,15 +112,4 @@ var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], voi
|
|
|
122
112
|
});
|
|
123
113
|
}); };
|
|
124
114
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
125
|
-
var getDynamicMultiplier = function (_a) {
|
|
126
|
-
var availabilityRatio = _a.availabilityRatio, isNearFuture = _a.isNearFuture;
|
|
127
|
-
if (availabilityRatio <= 0.02)
|
|
128
|
-
return isNearFuture ? 1.5 : 1.4;
|
|
129
|
-
if (availabilityRatio <= 0.5)
|
|
130
|
-
return isNearFuture ? 1.4 : 1.2;
|
|
131
|
-
if (availabilityRatio < 1)
|
|
132
|
-
return isNearFuture ? 1.2 : 1.05;
|
|
133
|
-
return isNearFuture ? 1.1 : 1.0;
|
|
134
|
-
};
|
|
135
|
-
exports.getDynamicMultiplier = getDynamicMultiplier;
|
|
136
115
|
//# 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,eAAA,EACT,wBAAwB,8BAAA,EACxB,mBAAmB,yBAAA;;;;gBAcb,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;gBAEpC,eAAe,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,oBAAoB,EAAtB,CAAsB,CAAC,CAAA;gBAChF,WAAW,GAAG,IAAI,GAAG,CACzB,eAAe,CAAC,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA;oBAC7B,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;oBACtD,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;oBACnC,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG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