@hyper.software/common-helpers 2.2.53 → 2.2.55
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,10 +1,18 @@
|
|
|
1
|
-
import { ICompany,
|
|
2
|
-
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, }: {
|
|
1
|
+
import { ICompany, IRoomTypePricePlanPricingInformation, IDynamicPricing } from '../../interfaces';
|
|
2
|
+
export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, roomTypeId, companyId, getRoomTypesAvailability, getRoomsByCompanyId, }: {
|
|
3
3
|
currentPricing: IRoomTypePricePlanPricingInformation;
|
|
4
4
|
dynamicPricing: IDynamicPricing;
|
|
5
|
-
existingBasePriceMap:
|
|
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
|
+
}>;
|
|
7
15
|
}) => Promise<{
|
|
8
16
|
updatedPricing: IRoomTypePricePlanPricingInformation;
|
|
9
|
-
updatedBasePriceMap:
|
|
17
|
+
updatedBasePriceMap: Record<string, number>;
|
|
10
18
|
}>;
|
|
@@ -52,54 +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
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
57
|
+
var basePriceMap, resultPricing, period, holidayDateSet, _i, period_1, dateStr, date, current, baseForToday, isAffectedHoliday, rawPrice;
|
|
58
|
+
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company, roomTypeId = _b.roomTypeId, companyId = _b.companyId, getRoomTypesAvailability = _b.getRoomTypesAvailability, getRoomsByCompanyId = _b.getRoomsByCompanyId;
|
|
59
|
+
return __generator(this, function (_c) {
|
|
60
|
+
switch (_c.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
63
|
+
resultPricing = {};
|
|
64
|
+
period = Object.keys(currentPricing);
|
|
65
|
+
return [4 /*yield*/, Promise.all([getRoomTypesAvailability(companyId, [roomTypeId], { period: period }), getRoomsByCompanyId(companyId)])];
|
|
66
|
+
case 1:
|
|
67
|
+
_c.sent();
|
|
68
|
+
holidayDateSet = new Set((company.holidays || [])
|
|
69
|
+
.filter(function (h) { return h.enableDynamicPricing; })
|
|
70
|
+
.flatMap(function (h) { return [
|
|
71
|
+
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
72
|
+
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
73
|
+
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
74
|
+
]; }));
|
|
75
|
+
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
76
|
+
dateStr = period_1[_i];
|
|
77
|
+
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
78
|
+
if (!date.isValid())
|
|
79
|
+
continue;
|
|
80
|
+
current = currentPricing[dateStr];
|
|
81
|
+
if (!(dateStr in basePriceMap)) {
|
|
82
|
+
basePriceMap[dateStr] = current;
|
|
83
|
+
}
|
|
84
|
+
baseForToday = basePriceMap[dateStr];
|
|
85
|
+
isAffectedHoliday = holidayDateSet.has(dateStr);
|
|
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
|
+
}
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
updatedPricing[dateStr] = Math.round(adjustedPrice);
|
|
97
|
-
}
|
|
97
|
+
return [2 /*return*/, {
|
|
98
|
+
updatedPricing: resultPricing,
|
|
99
|
+
updatedBasePriceMap: basePriceMap,
|
|
100
|
+
}];
|
|
98
101
|
}
|
|
99
|
-
return [2 /*return*/, {
|
|
100
|
-
updatedPricing: __assign(__assign({}, currentPricing), updatedPricing),
|
|
101
|
-
updatedBasePriceMap: updatedBasePriceMap,
|
|
102
|
-
}];
|
|
103
102
|
});
|
|
104
103
|
}); };
|
|
105
104
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
@@ -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,EAkB7C;;QAjBC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA,EACP,UAAU,gBAAA,EACV,SAAS,eAAA,EACT,wBAAwB,8BAAA,EACxB,mBAAmB,yBAAA;;;;gBAcb,YAAY,yBAAQ,cAAc,CAAC,SAAS,GAAK,oBAAoB,CAAE,CAAA;gBACvE,aAAa,GAAyC,EAAE,CAAA;gBAExD,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;gBAE1C,qBAAM,OAAO,CAAC,GAAG,CAAC,CAAC,wBAAwB,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,EAAA;;gBAAlH,SAAkH,CAAA;gBAE5G,cAAc,GAAG,IAAI,GAAG,CAC5B,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;qBACrB,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,oBAAoB,EAAtB,CAAsB,CAAC;qBACrC,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA;oBACd,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;oBACtD,IAAA,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