@hyper.software/common-helpers 2.2.52 → 2.2.54
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,18 +1,10 @@
|
|
|
1
|
-
import { ICompany, IRoomTypePricePlanPricingInformation,
|
|
1
|
+
import { ICompany, IDynamicPricing, IRoomTypePricePlanPricingInformation, IDynamicPricingBasePriceInformation } from '../../interfaces';
|
|
2
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
|
}>;
|
|
@@ -53,54 +53,54 @@ 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 _g;
|
|
56
|
+
var updatedPricing, updatedBasePriceMap, _i, _c, holiday, holidayDate, affectedDates, _d, affectedDates_1, dateStr, manualPrice, basePrice, isManuallyOverridden, adjustment, adjustedPrice;
|
|
57
|
+
var _e, _f, _g;
|
|
58
58
|
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
59
59
|
return __generator(this, function (_h) {
|
|
60
|
-
basePriceMap = __assign({}, existingBasePriceMap);
|
|
61
60
|
updatedPricing = {};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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)
|
|
66
71
|
continue;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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'),
|
|
72
77
|
];
|
|
73
|
-
for (_d = 0,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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;
|
|
78
86
|
}
|
|
87
|
+
isManuallyOverridden = manualPrice !== basePrice;
|
|
88
|
+
if (isManuallyOverridden) {
|
|
89
|
+
updatedPricing[dateStr] = manualPrice;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (!(dynamicPricing === null || dynamicPricing === void 0 ? void 0 : dynamicPricing.isActive))
|
|
93
|
+
continue;
|
|
94
|
+
adjustment = (_g = dynamicPricing.amount) !== null && _g !== void 0 ? _g : Math.round(basePrice * 0.05);
|
|
95
|
+
adjustedPrice = dynamicPricing.type === 'DECREASE'
|
|
96
|
+
? Math.max(basePrice - adjustment, 0)
|
|
97
|
+
: Math.min(basePrice + adjustment, basePrice + 70);
|
|
98
|
+
updatedPricing[dateStr] = Math.round(adjustedPrice);
|
|
79
99
|
}
|
|
80
100
|
}
|
|
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));
|
|
100
|
-
}
|
|
101
101
|
return [2 /*return*/, {
|
|
102
|
-
updatedPricing: updatedPricing,
|
|
103
|
-
updatedBasePriceMap:
|
|
102
|
+
updatedPricing: __assign(__assign({}, currentPricing), updatedPricing),
|
|
103
|
+
updatedBasePriceMap: updatedBasePriceMap,
|
|
104
104
|
}];
|
|
105
105
|
});
|
|
106
106
|
}); };
|
|
@@ -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,EAAE,CAAC;YAA9B,OAAO;YAChB,IAAI,CAAC,OAAO,CAAC,oBAAoB;gBAAE,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