@hyper.software/common-helpers 2.2.68 → 2.2.70
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,17 +1,9 @@
|
|
|
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>;
|
|
@@ -55,50 +55,45 @@ 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
57
|
var basePriceMap, resultPricing, period, holidayDateSet, _i, period_1, dateStr, date, current, baseForToday, isAffectedHoliday, rawPrice;
|
|
58
|
-
var
|
|
59
|
-
|
|
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
|
-
if (dynamicPricing.isActive && isAffectedHoliday) {
|
|
87
|
-
rawPrice = baseForToday + (dynamicPricing.amount || Math.round(baseForToday * 0.05));
|
|
88
|
-
if (rawPrice > baseForToday + 70) {
|
|
89
|
-
rawPrice = baseForToday + 70;
|
|
90
|
-
}
|
|
91
|
-
resultPricing[dateStr] = Math.round(rawPrice);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
resultPricing[dateStr] = baseForToday;
|
|
95
|
-
}
|
|
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
|
+
holidayDateSet = new Set((company.holidays || [])
|
|
65
|
+
.filter(function (h) { return h.enableDynamicPricing; })
|
|
66
|
+
.flatMap(function (h) { return [
|
|
67
|
+
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
68
|
+
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
69
|
+
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
70
|
+
]; }));
|
|
71
|
+
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
72
|
+
dateStr = period_1[_i];
|
|
73
|
+
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
74
|
+
if (!date.isValid())
|
|
75
|
+
continue;
|
|
76
|
+
current = currentPricing[dateStr];
|
|
77
|
+
if (dynamicPricing.isActive && !(dateStr in basePriceMap) && current != null) {
|
|
78
|
+
basePriceMap[dateStr] = current;
|
|
79
|
+
}
|
|
80
|
+
baseForToday = basePriceMap[dateStr];
|
|
81
|
+
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
82
|
+
if (dynamicPricing.isActive && isAffectedHoliday) {
|
|
83
|
+
rawPrice = baseForToday + ((_c = dynamicPricing.amount) !== null && _c !== void 0 ? _c : Math.round(baseForToday * 0.05));
|
|
84
|
+
if (rawPrice > baseForToday + 70) {
|
|
85
|
+
rawPrice = baseForToday + 70;
|
|
96
86
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
87
|
+
resultPricing[dateStr] = Math.round(rawPrice);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
resultPricing[dateStr] = baseForToday;
|
|
91
|
+
}
|
|
101
92
|
}
|
|
93
|
+
return [2 /*return*/, {
|
|
94
|
+
updatedPricing: resultPricing,
|
|
95
|
+
updatedBasePriceMap: basePriceMap,
|
|
96
|
+
}];
|
|
102
97
|
});
|
|
103
98
|
}); };
|
|
104
99
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
@@ -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,o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