@hyper.software/common-helpers 2.2.47 → 2.2.48
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,5 +1,5 @@
|
|
|
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>;
|
|
@@ -52,46 +52,57 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.calculateDynamicPricing = void 0;
|
|
54
54
|
var moment_1 = __importDefault(require("moment"));
|
|
55
|
+
var dateService_1 = require("../dateService/dateService");
|
|
55
56
|
var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
56
|
-
var basePriceMap,
|
|
57
|
+
var basePriceMap, resultPricing, period, holidayDateSet, today, _i, period_1, dateStr, date, current, base, baseForToday, leadTimeDays, isAffectedHoliday, bookingIncrement, leadTimeMultiplier, rawPrice;
|
|
57
58
|
var _c;
|
|
58
|
-
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
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;
|
|
59
60
|
return __generator(this, function (_d) {
|
|
60
|
-
|
|
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
|
-
|
|
61
|
+
switch (_d.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
64
|
+
resultPricing = {};
|
|
65
|
+
period = Object.keys(currentPricing);
|
|
66
|
+
return [4 /*yield*/, Promise.all([getRoomTypesAvailability(companyId, [roomTypeId], { period: period }), getRoomsByCompanyId(companyId)])];
|
|
67
|
+
case 1:
|
|
68
|
+
_d.sent();
|
|
69
|
+
holidayDateSet = new Set((company.holidays || [])
|
|
70
|
+
.filter(function (h) { return h.enableDynamicPricing; })
|
|
71
|
+
.flatMap(function (h) { return [
|
|
72
|
+
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
73
|
+
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
74
|
+
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
75
|
+
]; }));
|
|
76
|
+
today = (0, moment_1.default)();
|
|
77
|
+
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
78
|
+
dateStr = period_1[_i];
|
|
79
|
+
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
80
|
+
if (!date.isValid())
|
|
81
|
+
continue;
|
|
82
|
+
current = currentPricing[dateStr];
|
|
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];
|
|
88
|
+
leadTimeDays = date.diff(today, 'days');
|
|
89
|
+
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
90
|
+
if (dynamicPricing.isActive && isAffectedHoliday) {
|
|
91
|
+
bookingIncrement = 1.05;
|
|
92
|
+
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
93
|
+
rawPrice = baseForToday * bookingIncrement * leadTimeMultiplier;
|
|
94
|
+
rawPrice = Math.min(rawPrice, baseForToday + 70, baseForToday * 1.45);
|
|
95
|
+
resultPricing[dateStr] = Math.round(rawPrice);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
resultPricing[dateStr] = base;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return [2 /*return*/, {
|
|
102
|
+
updatedPricing: resultPricing,
|
|
103
|
+
updatedBasePriceMap: basePriceMap,
|
|
104
|
+
}];
|
|
90
105
|
}
|
|
91
|
-
return [2 /*return*/, {
|
|
92
|
-
updatedPricing: updatedPricing,
|
|
93
|
-
updatedBasePriceMap: basePriceMap,
|
|
94
|
-
}];
|
|
95
106
|
});
|
|
96
107
|
}); };
|
|
97
108
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;
|
|
1
|
+
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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