@hyper.software/common-helpers 2.10.30 → 2.10.32
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.
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { ICompany, IRoomTypePricePlanPricingInformation, IDynamicPricing } from '../../interfaces';
|
|
2
|
-
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, }: {
|
|
2
|
+
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, roomTypeId, companyId, getRoomTypesAvailability, getRoomsByCompanyId, }: {
|
|
3
3
|
currentPricing: IRoomTypePricePlanPricingInformation;
|
|
4
4
|
dynamicPricing: IDynamicPricing;
|
|
5
5
|
existingBasePriceMap: Record<string, number>;
|
|
6
6
|
company: ICompany;
|
|
7
7
|
roomTypeId: string;
|
|
8
8
|
companyId: string;
|
|
9
|
+
getRoomTypesAvailability: (companyId: string, roomTypeIds: string[], options: {
|
|
10
|
+
period: string[];
|
|
11
|
+
}) => Promise<any>;
|
|
12
|
+
getRoomsByCompanyId: (companyId: string) => Promise<{
|
|
13
|
+
list: any[];
|
|
14
|
+
}>;
|
|
9
15
|
}) => Promise<{
|
|
10
16
|
updatedPricing: IRoomTypePricePlanPricingInformation;
|
|
11
17
|
updatedBasePriceMap: Record<string, number>;
|
|
12
18
|
}>;
|
|
19
|
+
export declare const getDynamicMultiplier: ({ availabilityRatio, isNearFuture, }: {
|
|
20
|
+
availabilityRatio: number;
|
|
21
|
+
isNearFuture: boolean;
|
|
22
|
+
}) => number;
|
|
@@ -50,61 +50,91 @@ 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.calculateDynamicPricing = void 0;
|
|
53
|
+
exports.getDynamicMultiplier = 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, holidayDateSet, today, _i, period_1, dateStr, date, current, base,
|
|
58
|
-
var
|
|
59
|
-
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
60
|
-
return __generator(this, function (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
57
|
+
var basePriceMap, resultPricing, period, _c, roomTypesAvailability, roomsData, roomTypeAvailability, totalRooms, start, end, holidayDateSet, today, _i, period_1, dateStr, date, current, base, availableRooms, availabilityRatio, leadTimeDays, isNearHoliday, isNearFuture, isAffectedHoliday, occupancyMultiplier, leadTimeMultiplier, rawPrice, cappedPrice, expected;
|
|
58
|
+
var _d, _e, _f, _g, _h;
|
|
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 (_j) {
|
|
61
|
+
switch (_j.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
64
|
+
resultPricing = {};
|
|
65
|
+
period = Object.keys(currentPricing);
|
|
66
|
+
return [4 /*yield*/, Promise.all([
|
|
67
|
+
getRoomTypesAvailability(companyId, [roomTypeId], { period: period }),
|
|
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
|
+
start = (0, moment_1.default)(dynamicPricing.startDate);
|
|
75
|
+
end = (0, moment_1.default)(dynamicPricing.endDate);
|
|
76
|
+
holidayDateSet = new Set((company.holidays || [])
|
|
77
|
+
.filter(function (h) {
|
|
78
|
+
var holidayMoment = (0, moment_1.default)(h.date);
|
|
79
|
+
return (h.enableDynamicPricing &&
|
|
80
|
+
holidayMoment.isSameOrAfter(start.clone().subtract(1, 'day')) &&
|
|
81
|
+
holidayMoment.isSameOrBefore(end.clone().add(1, 'day')));
|
|
82
|
+
})
|
|
83
|
+
.flatMap(function (h) { return [
|
|
84
|
+
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
85
|
+
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
86
|
+
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
87
|
+
]; }));
|
|
88
|
+
today = (0, moment_1.default)();
|
|
89
|
+
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
90
|
+
dateStr = period_1[_i];
|
|
91
|
+
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
92
|
+
if (!date.isValid())
|
|
93
|
+
continue;
|
|
94
|
+
current = currentPricing[dateStr];
|
|
95
|
+
base = (_g = basePriceMap[dateStr]) !== null && _g !== void 0 ? _g : current;
|
|
96
|
+
availableRooms = (_h = roomTypeAvailability[dateStr]) !== null && _h !== void 0 ? _h : 0;
|
|
97
|
+
availabilityRatio = availableRooms / totalRooms;
|
|
98
|
+
leadTimeDays = date.diff(today, 'days');
|
|
99
|
+
isNearHoliday = leadTimeDays <= 7;
|
|
100
|
+
isNearFuture = leadTimeDays < 30;
|
|
101
|
+
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
102
|
+
if (isAffectedHoliday) {
|
|
103
|
+
if (!(dateStr in basePriceMap)) {
|
|
104
|
+
basePriceMap[dateStr] = base;
|
|
105
|
+
}
|
|
106
|
+
occupancyMultiplier = (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture });
|
|
107
|
+
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
108
|
+
rawPrice = base * occupancyMultiplier * leadTimeMultiplier;
|
|
109
|
+
cappedPrice = isNearHoliday && availableRooms <= 1 ? Math.min(rawPrice, base + 70) : Math.min(rawPrice, base * 1.45);
|
|
110
|
+
resultPricing[dateStr] = Math.round(cappedPrice);
|
|
111
|
+
}
|
|
112
|
+
else if (!dynamicPricing.isActive && base !== undefined) {
|
|
113
|
+
resultPricing[dateStr] = base;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
expected = base ? Math.round(base * (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture })) : current;
|
|
117
|
+
resultPricing[dateStr] =
|
|
118
|
+
current === expected || current === Math.round((base !== null && base !== void 0 ? base : 0) * 1.2) ? (base !== null && base !== void 0 ? base : current) : current;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return [2 /*return*/, {
|
|
122
|
+
updatedPricing: resultPricing,
|
|
123
|
+
updatedBasePriceMap: basePriceMap,
|
|
124
|
+
}];
|
|
102
125
|
}
|
|
103
|
-
return [2 /*return*/, {
|
|
104
|
-
updatedPricing: resultPricing,
|
|
105
|
-
updatedBasePriceMap: basePriceMap,
|
|
106
|
-
}];
|
|
107
126
|
});
|
|
108
127
|
}); };
|
|
109
128
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
129
|
+
var getDynamicMultiplier = function (_a) {
|
|
130
|
+
var availabilityRatio = _a.availabilityRatio, isNearFuture = _a.isNearFuture;
|
|
131
|
+
if (availabilityRatio <= 0.02)
|
|
132
|
+
return isNearFuture ? 1.5 : 1.4;
|
|
133
|
+
if (availabilityRatio <= 0.5)
|
|
134
|
+
return isNearFuture ? 1.4 : 1.2;
|
|
135
|
+
if (availabilityRatio < 1)
|
|
136
|
+
return isNearFuture ? 1.2 : 1.05;
|
|
137
|
+
return isNearFuture ? 1.1 : 1.0;
|
|
138
|
+
};
|
|
139
|
+
exports.getDynamicMultiplier = getDynamicMultiplier;
|
|
110
140
|
//# 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,
|
|
1
|
+
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings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