@hyper.software/common-helpers 2.2.33 → 2.2.34
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,27 +50,22 @@ 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
|
|
57
|
+
var basePriceMap, resultPricing, period, holidayDateSet, today, _i, period_1, dateStr, date, current, base, baseForToday, leadTimeDays, isAffectedHoliday, bookingIncrement, leadTimeMultiplier, rawPrice;
|
|
58
|
+
var _c;
|
|
59
59
|
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 (
|
|
60
|
+
return __generator(this, function (_d) {
|
|
61
|
+
switch (_d.label) {
|
|
62
62
|
case 0:
|
|
63
63
|
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
64
64
|
resultPricing = {};
|
|
65
65
|
period = Object.keys(currentPricing);
|
|
66
|
-
return [4 /*yield*/, Promise.all([
|
|
67
|
-
getRoomTypesAvailability(companyId, [roomTypeId], { period: period }),
|
|
68
|
-
getRoomsByCompanyId(companyId),
|
|
69
|
-
])];
|
|
66
|
+
return [4 /*yield*/, Promise.all([getRoomTypesAvailability(companyId, [roomTypeId], { period: period }), getRoomsByCompanyId(companyId)])];
|
|
70
67
|
case 1:
|
|
71
|
-
|
|
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;
|
|
68
|
+
_d.sent();
|
|
74
69
|
holidayDateSet = new Set((company.holidays || [])
|
|
75
70
|
.filter(function (h) { return h.enableDynamicPricing; })
|
|
76
71
|
.flatMap(function (h) { return [
|
|
@@ -85,33 +80,22 @@ var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], voi
|
|
|
85
80
|
if (!date.isValid())
|
|
86
81
|
continue;
|
|
87
82
|
current = currentPricing[dateStr];
|
|
88
|
-
base = (
|
|
89
|
-
|
|
90
|
-
|
|
83
|
+
base = (_c = basePriceMap[dateStr]) !== null && _c !== void 0 ? _c : current;
|
|
84
|
+
if (!(dateStr in basePriceMap)) {
|
|
85
|
+
basePriceMap[dateStr] = base;
|
|
86
|
+
}
|
|
87
|
+
baseForToday = basePriceMap[dateStr];
|
|
91
88
|
leadTimeDays = date.diff(today, 'days');
|
|
92
|
-
isNearHoliday = leadTimeDays <= 7;
|
|
93
|
-
isNearFuture = leadTimeDays < 30;
|
|
94
89
|
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
95
|
-
if (isAffectedHoliday) {
|
|
96
|
-
|
|
97
|
-
basePriceMap[dateStr] = base;
|
|
98
|
-
}
|
|
99
|
-
baseForToday = basePriceMap[dateStr];
|
|
100
|
-
occupancyMultiplier = (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture });
|
|
90
|
+
if (dynamicPricing.isActive && isAffectedHoliday) {
|
|
91
|
+
bookingIncrement = 1.05;
|
|
101
92
|
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
102
|
-
rawPrice = baseForToday *
|
|
103
|
-
|
|
104
|
-
|
|
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;
|
|
93
|
+
rawPrice = baseForToday * bookingIncrement * leadTimeMultiplier;
|
|
94
|
+
rawPrice = Math.min(rawPrice, baseForToday + 70, baseForToday * 1.45);
|
|
95
|
+
resultPricing[dateStr] = Math.round(rawPrice);
|
|
110
96
|
}
|
|
111
97
|
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;
|
|
98
|
+
resultPricing[dateStr] = base;
|
|
115
99
|
}
|
|
116
100
|
}
|
|
117
101
|
return [2 /*return*/, {
|
|
@@ -122,15 +106,4 @@ var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], voi
|
|
|
122
106
|
});
|
|
123
107
|
}); };
|
|
124
108
|
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
109
|
//# 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;;;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,YAAY,yBAAQ,cAAc,CAAC,SAAS,GAAK,oBAAoB,CAAE,CAAA;gBACvE,aAAa,GAAyC,EAAE,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,EAkB7C;;;QAjBC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA,EACP,UAAU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