@hyper.software/common-helpers 2.2.51 → 2.2.53
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,10 @@
|
|
|
1
|
-
import { ICompany, IRoomTypePricePlanPricingInformation,
|
|
2
|
-
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company,
|
|
1
|
+
import { ICompany, IDynamicPricing, IRoomTypePricePlanPricingInformation, IDynamicPricingBasePriceInformation } from '../../interfaces';
|
|
2
|
+
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, }: {
|
|
3
3
|
currentPricing: IRoomTypePricePlanPricingInformation;
|
|
4
4
|
dynamicPricing: IDynamicPricing;
|
|
5
|
-
existingBasePriceMap:
|
|
5
|
+
existingBasePriceMap: IDynamicPricingBasePriceInformation;
|
|
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
|
-
updatedBasePriceMap:
|
|
9
|
+
updatedBasePriceMap: IDynamicPricingBasePriceInformation;
|
|
18
10
|
}>;
|
|
19
|
-
export declare const getDynamicMultiplier: ({ availabilityRatio, isNearFuture, }: {
|
|
20
|
-
availabilityRatio: number;
|
|
21
|
-
isNearFuture: boolean;
|
|
22
|
-
}) => number;
|
|
@@ -50,87 +50,57 @@ 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
|
-
var dateService_1 = require("../dateService/dateService");
|
|
56
55
|
var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
57
|
-
var
|
|
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
|
-
isNearHoliday = leadTimeDays <= 7;
|
|
93
|
-
isNearFuture = leadTimeDays < 30;
|
|
94
|
-
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
95
|
-
if (isAffectedHoliday) {
|
|
96
|
-
if (!(dateStr in basePriceMap)) {
|
|
97
|
-
basePriceMap[dateStr] = base;
|
|
98
|
-
}
|
|
99
|
-
baseForToday = basePriceMap[dateStr];
|
|
100
|
-
occupancyMultiplier = (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture });
|
|
101
|
-
leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
|
|
102
|
-
rawPrice = baseForToday * occupancyMultiplier * leadTimeMultiplier;
|
|
103
|
-
cappedPrice = isNearHoliday && availableRooms <= 1
|
|
104
|
-
? Math.min(rawPrice, baseForToday + 70)
|
|
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;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
expected = base ? Math.round(base * (0, exports.getDynamicMultiplier)({ availabilityRatio: availabilityRatio, isNearFuture: isNearFuture })) : current;
|
|
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;
|
|
115
|
-
}
|
|
56
|
+
var updatedPricing, updatedBasePriceMap, _i, _c, holiday, holidayDate, affectedDates, _d, affectedDates_1, dateStr, manualPrice, basePrice, isManuallyOverridden, adjustment, adjustedPrice;
|
|
57
|
+
var _e, _f, _g;
|
|
58
|
+
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
59
|
+
return __generator(this, function (_h) {
|
|
60
|
+
updatedPricing = {};
|
|
61
|
+
updatedBasePriceMap = __assign({}, existingBasePriceMap);
|
|
62
|
+
if (!(dynamicPricing === null || dynamicPricing === void 0 ? void 0 : dynamicPricing.isActive) || !((_e = company.holidays) === null || _e === void 0 ? void 0 : _e.length)) {
|
|
63
|
+
return [2 /*return*/, {
|
|
64
|
+
updatedPricing: currentPricing,
|
|
65
|
+
updatedBasePriceMap: updatedBasePriceMap,
|
|
66
|
+
}];
|
|
67
|
+
}
|
|
68
|
+
for (_i = 0, _c = company.holidays; _i < _c.length; _i++) {
|
|
69
|
+
holiday = _c[_i];
|
|
70
|
+
if (!holiday.enableDynamicPricing)
|
|
71
|
+
continue;
|
|
72
|
+
holidayDate = (0, moment_1.default)(holiday.date);
|
|
73
|
+
affectedDates = [
|
|
74
|
+
holidayDate.clone().subtract(1, 'day').format('YYYY-MM-DD'),
|
|
75
|
+
holidayDate.format('YYYY-MM-DD'),
|
|
76
|
+
holidayDate.clone().add(1, 'day').format('YYYY-MM-DD'),
|
|
77
|
+
];
|
|
78
|
+
for (_d = 0, affectedDates_1 = affectedDates; _d < affectedDates_1.length; _d++) {
|
|
79
|
+
dateStr = affectedDates_1[_d];
|
|
80
|
+
manualPrice = currentPricing[dateStr];
|
|
81
|
+
if (manualPrice === undefined)
|
|
82
|
+
continue;
|
|
83
|
+
basePrice = (_f = updatedBasePriceMap[dateStr]) !== null && _f !== void 0 ? _f : manualPrice;
|
|
84
|
+
if (!(dateStr in updatedBasePriceMap)) {
|
|
85
|
+
updatedBasePriceMap[dateStr] = basePrice;
|
|
86
|
+
}
|
|
87
|
+
isManuallyOverridden = manualPrice !== basePrice;
|
|
88
|
+
if (isManuallyOverridden) {
|
|
89
|
+
updatedPricing[dateStr] = manualPrice;
|
|
90
|
+
continue;
|
|
116
91
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
92
|
+
adjustment = (_g = dynamicPricing.amount) !== null && _g !== void 0 ? _g : Math.round(basePrice * 0.05);
|
|
93
|
+
adjustedPrice = dynamicPricing.type === 'DECREASE'
|
|
94
|
+
? Math.max(basePrice - adjustment, 0)
|
|
95
|
+
: Math.min(basePrice + adjustment, basePrice + 70);
|
|
96
|
+
updatedPricing[dateStr] = Math.round(adjustedPrice);
|
|
97
|
+
}
|
|
121
98
|
}
|
|
99
|
+
return [2 /*return*/, {
|
|
100
|
+
updatedPricing: __assign(__assign({}, currentPricing), updatedPricing),
|
|
101
|
+
updatedBasePriceMap: updatedBasePriceMap,
|
|
102
|
+
}];
|
|
122
103
|
});
|
|
123
104
|
}); };
|
|
124
105
|
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
106
|
//# sourceMappingURL=dynamicPricingService.js.map
|
|
@@ -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;AAQpB,IAAM,uBAAuB,GAAG,iEAAO,EAU7C;;;QATC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA;;QAUD,cAAc,GAAyC,EAAE,CAAA;QACzD,mBAAmB,gBAA6C,oBAAoB,CAAE,CAAA;QAE5F,IAAI,CAAC,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,QAAQ,CAAA,IAAI,CAAC,CAAA,MAAA,OAAO,CAAC,QAAQ,0CAAE,MAAM,CAAA,EAAE,CAAC;YAC3D,sBAAO;oBACL,cAAc,EAAE,cAAc;oBAC9B,mBAAmB,EAAE,mBAAmB;iBACzC,EAAA;QACH,CAAC;QAED,WAAsC,EAAhB,KAAA,OAAO,CAAC,QAAQ,EAAhB,cAAgB,EAAhB,IAAgB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