@hyper.software/common-helpers 2.10.39 → 2.10.40
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,9 +1,9 @@
|
|
|
1
|
-
import { IRoomTypePricePlanPricingInformation, IDynamicPricing } from '../../interfaces';
|
|
2
|
-
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing,
|
|
1
|
+
import { ICompany, IRoomTypePricePlanPricingInformation, IDynamicPricing } from '../../interfaces';
|
|
2
|
+
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, }: {
|
|
3
3
|
currentPricing: IRoomTypePricePlanPricingInformation;
|
|
4
4
|
dynamicPricing: IDynamicPricing;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
existingBasePriceMap: Record<string, number>;
|
|
6
|
+
company: ICompany;
|
|
7
7
|
}) => Promise<{
|
|
8
8
|
updatedPricing: IRoomTypePricePlanPricingInformation;
|
|
9
9
|
updatedBasePriceMap: Record<string, number>;
|
|
@@ -52,44 +52,53 @@ 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
|
|
57
|
-
var
|
|
58
|
-
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing,
|
|
59
|
-
return __generator(this, function (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (manualPrice !== undefined) {
|
|
74
|
-
updatedPricing[dateStr] = manualPrice;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
currentBase = (_e = basePriceMap[dateStr]) !== null && _e !== void 0 ? _e : currentPricing[dateStr];
|
|
78
|
-
if (!currentBase)
|
|
57
|
+
var basePriceMap, resultPricing, holidayDateSet, _i, _c, dateStr, date, current, base, baseForToday, increasedPrice;
|
|
58
|
+
var _d;
|
|
59
|
+
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
60
|
+
return __generator(this, function (_e) {
|
|
61
|
+
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
62
|
+
resultPricing = {};
|
|
63
|
+
holidayDateSet = new Set((company.holidays || [])
|
|
64
|
+
.filter(function (h) { return h.enableDynamicPricing; })
|
|
65
|
+
.flatMap(function (h) { return [
|
|
66
|
+
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
67
|
+
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
68
|
+
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
69
|
+
]; }));
|
|
70
|
+
for (_i = 0, _c = Object.keys(currentPricing); _i < _c.length; _i++) {
|
|
71
|
+
dateStr = _c[_i];
|
|
72
|
+
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
73
|
+
if (!date.isValid())
|
|
79
74
|
continue;
|
|
75
|
+
current = currentPricing[dateStr];
|
|
76
|
+
base = (_d = basePriceMap[dateStr]) !== null && _d !== void 0 ? _d : current;
|
|
80
77
|
if (!(dateStr in basePriceMap)) {
|
|
81
|
-
basePriceMap[dateStr] =
|
|
78
|
+
basePriceMap[dateStr] = base;
|
|
82
79
|
}
|
|
83
|
-
if (dynamicPricing.isActive) {
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
if (dynamicPricing.isActive && holidayDateSet.has(dateStr)) {
|
|
81
|
+
baseForToday = basePriceMap[dateStr];
|
|
82
|
+
increasedPrice = baseForToday;
|
|
83
|
+
if (dynamicPricing.amount) {
|
|
84
|
+
if (dynamicPricing.type === 'INCREASE') {
|
|
85
|
+
increasedPrice = baseForToday + dynamicPricing.amount;
|
|
86
|
+
}
|
|
87
|
+
else if (dynamicPricing.type === 'DECREASE') {
|
|
88
|
+
increasedPrice = Math.max(0, baseForToday - dynamicPricing.amount);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
increasedPrice = Math.round(baseForToday * 1.05);
|
|
93
|
+
}
|
|
94
|
+
resultPricing[dateStr] = increasedPrice;
|
|
86
95
|
}
|
|
87
96
|
else {
|
|
88
|
-
|
|
97
|
+
resultPricing[dateStr] = base;
|
|
89
98
|
}
|
|
90
99
|
}
|
|
91
100
|
return [2 /*return*/, {
|
|
92
|
-
updatedPricing:
|
|
101
|
+
updatedPricing: resultPricing,
|
|
93
102
|
updatedBasePriceMap: basePriceMap,
|
|
94
103
|
}];
|
|
95
104
|
});
|
|
@@ -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;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,GA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