@hyper.software/common-helpers 2.2.48 → 2.2.50
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, }: {
|
|
3
3
|
currentPricing: IRoomTypePricePlanPricingInformation;
|
|
4
4
|
dynamicPricing: IDynamicPricing;
|
|
5
5
|
existingBasePriceMap: Record<string, number>;
|
|
@@ -52,57 +52,56 @@ 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");
|
|
56
55
|
var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
57
|
-
var basePriceMap,
|
|
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
|
-
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
|
-
}
|
|
56
|
+
var basePriceMap, updatedPricing, affectedDates, _i, _c, h, date, range, _d, range_1, d, _e, _f, dateStr, manualPrice, basePrice, isAffected, isManuallyOverridden, increased;
|
|
57
|
+
var _g;
|
|
58
|
+
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
59
|
+
return __generator(this, function (_h) {
|
|
60
|
+
basePriceMap = __assign({}, existingBasePriceMap);
|
|
61
|
+
updatedPricing = {};
|
|
62
|
+
affectedDates = new Set();
|
|
63
|
+
for (_i = 0, _c = company.holidays || []; _i < _c.length; _i++) {
|
|
64
|
+
h = _c[_i];
|
|
65
|
+
if (!h.enableDynamicPricing)
|
|
66
|
+
continue;
|
|
67
|
+
date = (0, moment_1.default)(h.date);
|
|
68
|
+
range = [
|
|
69
|
+
date.clone().subtract(1, 'day').format('YYYY-MM-DD'),
|
|
70
|
+
date.clone().format('YYYY-MM-DD'),
|
|
71
|
+
date.clone().add(1, 'day').format('YYYY-MM-DD'),
|
|
72
|
+
];
|
|
73
|
+
for (_d = 0, range_1 = range; _d < range_1.length; _d++) {
|
|
74
|
+
d = range_1[_d];
|
|
75
|
+
if ((!dynamicPricing.startDate || d >= dynamicPricing.startDate) &&
|
|
76
|
+
(!dynamicPricing.endDate || d <= dynamicPricing.endDate)) {
|
|
77
|
+
affectedDates.add(d);
|
|
100
78
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
for (_e = 0, _f = Object.keys(currentPricing); _e < _f.length; _e++) {
|
|
82
|
+
dateStr = _f[_e];
|
|
83
|
+
manualPrice = currentPricing[dateStr];
|
|
84
|
+
basePrice = (_g = basePriceMap[dateStr]) !== null && _g !== void 0 ? _g : manualPrice;
|
|
85
|
+
isAffected = affectedDates.has(dateStr);
|
|
86
|
+
isManuallyOverridden = manualPrice !== basePrice;
|
|
87
|
+
if (!(dateStr in basePriceMap)) {
|
|
88
|
+
basePriceMap[dateStr] = manualPrice;
|
|
89
|
+
}
|
|
90
|
+
if (!dynamicPricing.isActive || !isAffected) {
|
|
91
|
+
updatedPricing[dateStr] = basePrice;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (isManuallyOverridden) {
|
|
95
|
+
updatedPricing[dateStr] = manualPrice;
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
increased = basePrice + (dynamicPricing.amount || Math.round(basePrice * 0.05));
|
|
99
|
+
updatedPricing[dateStr] = Math.round(Math.min(increased, basePrice + 70));
|
|
105
100
|
}
|
|
101
|
+
return [2 /*return*/, {
|
|
102
|
+
updatedPricing: updatedPricing,
|
|
103
|
+
updatedBasePriceMap: basePriceMap,
|
|
104
|
+
}];
|
|
106
105
|
});
|
|
107
106
|
}); };
|
|
108
107
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAGpB,IAAM,uBAAuB,GAAG,iEAAO,EAc7C;;;QAbC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA;;QAcD,YAAY,gBAAQ,oBAAoB,CAAE,CAAA;QAC1C,cAAc,GAAyC,EAAE,CAAA;QAEzD,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QAEvC,WAAsC,EAAtB,KAAA,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAtB,cAAsB,EAAtB,IAAsB,EAAE,CAAC;YAA9B,CAAC;YACV,IAAI,CAAC,CAAC,CAAC,oBAAoB;gBAAE,SAAQ;YAE/B,IAAI,GAAG,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAA;YACrB,KAAK,GAAG;gBACZ,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;gBACpD,IAAI,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC;gBACjC,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;aAChD,CAAA;YAED,WAAqB,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK,EAAE,CAAC;gBAAb,CAAC;gBACV,IACE,CAAC,CAAC,cAAc,CAAC,SAAS,IAAI,CAAC,IAAI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