@hyper.software/common-helpers 2.10.31 → 2.10.33
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,22 +1,13 @@
|
|
|
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, }: {
|
|
3
3
|
currentPricing: IRoomTypePricePlanPricingInformation;
|
|
4
4
|
dynamicPricing: IDynamicPricing;
|
|
5
5
|
existingBasePriceMap: Record<string, number>;
|
|
6
6
|
company: ICompany;
|
|
7
|
-
roomTypeId: string;
|
|
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
|
-
}>;
|
|
15
7
|
}) => Promise<{
|
|
16
8
|
updatedPricing: IRoomTypePricePlanPricingInformation;
|
|
17
9
|
updatedBasePriceMap: Record<string, number>;
|
|
18
10
|
}>;
|
|
19
|
-
export declare const getDynamicMultiplier: ({
|
|
20
|
-
availabilityRatio: number;
|
|
11
|
+
export declare const getDynamicMultiplier: ({ isNearFuture }: {
|
|
21
12
|
isNearFuture: boolean;
|
|
22
13
|
}) => number;
|
|
@@ -54,79 +54,66 @@ 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,
|
|
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
|
-
isNearFuture = leadTimeDays < 30;
|
|
94
|
-
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
95
|
-
if (isAffectedHoliday) {
|
|
96
|
-
if (!(dateStr in basePriceMap)) {
|
|
97
|
-
basePriceMap[dateStr] = base;
|
|
98
|
-
}
|
|
99
|
-
occupancyMultiplier = (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture });
|
|
100
|
-
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
101
|
-
rawPrice = base * occupancyMultiplier * leadTimeMultiplier;
|
|
102
|
-
cappedPrice = isNearHoliday && availableRooms <= 1 ? Math.min(rawPrice, base + 70) : Math.min(rawPrice, base * 1.45);
|
|
103
|
-
resultPricing[dateStr] = Math.round(cappedPrice);
|
|
104
|
-
}
|
|
105
|
-
else if (!dynamicPricing.isActive && base !== undefined) {
|
|
106
|
-
resultPricing[dateStr] = base;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
expected = base ? Math.round(base * (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture })) : current;
|
|
110
|
-
resultPricing[dateStr] =
|
|
111
|
-
current === expected || current === Math.round((base !== null && base !== void 0 ? base : 0) * 1.2) ? (base !== null && base !== void 0 ? base : current) : current;
|
|
112
|
-
}
|
|
57
|
+
var basePriceMap, resultPricing, period, start, end, today, holidayDateSet, _i, period_1, dateStr, date, current, base, leadTimeDays, isNearHoliday, isNearFuture, isAffectedHoliday, leadTimeMultiplier, rawPrice, cappedPrice, expected;
|
|
58
|
+
var _c;
|
|
59
|
+
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
60
|
+
return __generator(this, function (_d) {
|
|
61
|
+
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
62
|
+
resultPricing = {};
|
|
63
|
+
period = Object.keys(currentPricing);
|
|
64
|
+
start = (0, moment_1.default)(dynamicPricing.startDate);
|
|
65
|
+
end = (0, moment_1.default)(dynamicPricing.endDate);
|
|
66
|
+
today = (0, moment_1.default)();
|
|
67
|
+
holidayDateSet = new Set((company.holidays || [])
|
|
68
|
+
.filter(function (h) {
|
|
69
|
+
var holidayMoment = (0, moment_1.default)(h.date);
|
|
70
|
+
return (h.enableDynamicPricing &&
|
|
71
|
+
holidayMoment.isSameOrAfter(start.clone().subtract(1, 'day')) &&
|
|
72
|
+
holidayMoment.isSameOrBefore(end.clone().add(1, 'day')));
|
|
73
|
+
})
|
|
74
|
+
.flatMap(function (h) { return [
|
|
75
|
+
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
76
|
+
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
77
|
+
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
78
|
+
]; }));
|
|
79
|
+
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
80
|
+
dateStr = period_1[_i];
|
|
81
|
+
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
82
|
+
if (!date.isValid())
|
|
83
|
+
continue;
|
|
84
|
+
current = currentPricing[dateStr];
|
|
85
|
+
base = (_c = basePriceMap[dateStr]) !== null && _c !== void 0 ? _c : current;
|
|
86
|
+
leadTimeDays = date.diff(today, 'days');
|
|
87
|
+
isNearHoliday = leadTimeDays <= 7;
|
|
88
|
+
isNearFuture = leadTimeDays < 30;
|
|
89
|
+
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
90
|
+
if (isAffectedHoliday) {
|
|
91
|
+
if (!(dateStr in basePriceMap)) {
|
|
92
|
+
basePriceMap[dateStr] = base;
|
|
113
93
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
94
|
+
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
95
|
+
rawPrice = base * leadTimeMultiplier;
|
|
96
|
+
cappedPrice = isNearHoliday ? Math.min(rawPrice, base + 70) : Math.min(rawPrice, base * 1.45);
|
|
97
|
+
resultPricing[dateStr] = Math.round(cappedPrice);
|
|
98
|
+
}
|
|
99
|
+
else if (!dynamicPricing.isActive && base !== undefined) {
|
|
100
|
+
resultPricing[dateStr] = base;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
expected = base ? Math.round(base * (0, exports.getDynamicMultiplier)({ isNearFuture: isNearFuture })) : current;
|
|
104
|
+
resultPricing[dateStr] =
|
|
105
|
+
current === expected || current === Math.round((base !== null && base !== void 0 ? base : 0) * 1.2) ? (base !== null && base !== void 0 ? base : current) : current;
|
|
106
|
+
}
|
|
118
107
|
}
|
|
108
|
+
return [2 /*return*/, {
|
|
109
|
+
updatedPricing: resultPricing,
|
|
110
|
+
updatedBasePriceMap: basePriceMap,
|
|
111
|
+
}];
|
|
119
112
|
});
|
|
120
113
|
}); };
|
|
121
114
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
122
115
|
var getDynamicMultiplier = function (_a) {
|
|
123
|
-
var
|
|
124
|
-
if (availabilityRatio <= 0.02)
|
|
125
|
-
return isNearFuture ? 1.5 : 1.4;
|
|
126
|
-
if (availabilityRatio <= 0.5)
|
|
127
|
-
return isNearFuture ? 1.4 : 1.2;
|
|
128
|
-
if (availabilityRatio < 1)
|
|
129
|
-
return isNearFuture ? 1.2 : 1.05;
|
|
116
|
+
var isNearFuture = _a.isNearFuture;
|
|
130
117
|
return isNearFuture ? 1.1 : 1.0;
|
|
131
118
|
};
|
|
132
119
|
exports.getDynamicMultiplier = getDynamicMultiplier;
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAE3B,0DAA0D;AAEnD,IAAM,uBAAuB,GAAG,iEAAO,EAU7C;;;QATC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA;;QAUD,YAAY,yBAAQ,cAAc,CAAC,SAAS,GAAK,oBAAoB,CAAE,CAAA;QACvE,aAAa,GAAyC,EAAE,CAAA;QAExD,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QACpC,KAAK,GAAG,IAAA,gBAAM,EAAC,cAAc,CAAC,SAAS,CAAC,CAAA;QACxC,GAAG,GAAG,IAAA,gBAAM,EAAC,cAAc,CAAC,OAAO,CAAC,CAAA;QACpC,KAAK,GAAG,IAAA,gBAAM,GAAE,CAAA;QAEhB,cA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