@hyper.software/common-helpers 2.10.39 → 2.10.41
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>;
|
|
@@ -53,43 +53,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
53
53
|
exports.calculateDynamicPricing = void 0;
|
|
54
54
|
var moment_1 = __importDefault(require("moment"));
|
|
55
55
|
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
|
-
|
|
56
|
+
var basePriceMap, resultPricing, affectedDates, _i, _c, holiday, date, _d, _e, dateStr, base, isAffected;
|
|
57
|
+
var _f;
|
|
58
|
+
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
59
|
+
return __generator(this, function (_g) {
|
|
60
|
+
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
61
|
+
resultPricing = {};
|
|
62
62
|
affectedDates = new Set();
|
|
63
|
-
for (_i = 0,
|
|
64
|
-
holiday =
|
|
65
|
-
|
|
63
|
+
for (_i = 0, _c = company.holidays || []; _i < _c.length; _i++) {
|
|
64
|
+
holiday = _c[_i];
|
|
65
|
+
if (!holiday.enableDynamicPricing)
|
|
66
|
+
continue;
|
|
67
|
+
date = (0, moment_1.default)(holiday.date);
|
|
66
68
|
affectedDates.add(date.clone().subtract(1, 'day').format('YYYY-MM-DD'));
|
|
67
69
|
affectedDates.add(date.format('YYYY-MM-DD'));
|
|
68
70
|
affectedDates.add(date.clone().add(1, 'day').format('YYYY-MM-DD'));
|
|
69
71
|
}
|
|
70
|
-
for (
|
|
71
|
-
dateStr = _d
|
|
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)
|
|
79
|
-
continue;
|
|
72
|
+
for (_d = 0, _e = Object.keys(currentPricing); _d < _e.length; _d++) {
|
|
73
|
+
dateStr = _e[_d];
|
|
74
|
+
base = (_f = basePriceMap[dateStr]) !== null && _f !== void 0 ? _f : currentPricing[dateStr];
|
|
80
75
|
if (!(dateStr in basePriceMap)) {
|
|
81
|
-
basePriceMap[dateStr] =
|
|
76
|
+
basePriceMap[dateStr] = base;
|
|
77
|
+
}
|
|
78
|
+
isAffected = affectedDates.has(dateStr);
|
|
79
|
+
if (dynamicPricing.isActive && isAffected) {
|
|
80
|
+
resultPricing[dateStr] = Math.round(base * 1.2);
|
|
82
81
|
}
|
|
83
|
-
if (dynamicPricing.isActive) {
|
|
84
|
-
|
|
85
|
-
updatedPricing[dateStr] = Math.round(currentBase * multiplier);
|
|
82
|
+
else if (!dynamicPricing.isActive && base !== undefined) {
|
|
83
|
+
resultPricing[dateStr] = base;
|
|
86
84
|
}
|
|
87
85
|
else {
|
|
88
|
-
|
|
86
|
+
resultPricing[dateStr] = currentPricing[dateStr];
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
return [2 /*return*/, {
|
|
92
|
-
updatedPricing:
|
|
90
|
+
updatedPricing: resultPricing,
|
|
93
91
|
updatedBasePriceMap: basePriceMap,
|
|
94
92
|
}];
|
|
95
93
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAGpB,IAAM,uBAAuB,GAAG,iEAAO,EAU7C;;;QATC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,
|
|
1
|
+
{"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAGpB,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,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QAEvC,WAA4C,EAAtB,KAAA,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAtB,cAAsB,EAAtB,IAAsB,EAAE,CAAC;YAApC,OAAO;YAChB,IAAI,CAAC,OAAO,CAAC,oBAAoB;gBAAE,SAAQ;YAErC,IAAI,GAAG,IAAA,gBAAM,EAAC,OAAO,CAAC,IAAI,CAAC,CAAA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