@hyper.software/common-helpers 2.2.48 → 2.2.49

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,5 +1,5 @@
1
1
  import { ICompany, IRoomTypePricePlanPricingInformation, IDynamicPricing } from '../../interfaces';
2
- export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, roomTypeId, companyId, getRoomTypesAvailability, getRoomsByCompanyId, }: {
2
+ export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, }: {
3
3
  currentPricing: IRoomTypePricePlanPricingInformation;
4
4
  dynamicPricing: IDynamicPricing;
5
5
  existingBasePriceMap: Record<string, number>;
@@ -52,57 +52,45 @@ 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");
56
55
  var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var basePriceMap, resultPricing, period, holidayDateSet, today, _i, period_1, dateStr, date, current, base, baseForToday, leadTimeDays, isAffectedHoliday, bookingIncrement, leadTimeMultiplier, rawPrice;
58
- var _c;
59
- 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;
60
- return __generator(this, function (_d) {
61
- switch (_d.label) {
62
- case 0:
63
- basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
64
- resultPricing = {};
65
- period = Object.keys(currentPricing);
66
- return [4 /*yield*/, Promise.all([getRoomTypesAvailability(companyId, [roomTypeId], { period: period }), getRoomsByCompanyId(companyId)])];
67
- case 1:
68
- _d.sent();
69
- holidayDateSet = new Set((company.holidays || [])
70
- .filter(function (h) { return h.enableDynamicPricing; })
71
- .flatMap(function (h) { return [
72
- (0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
73
- (0, moment_1.default)(h.date).format('YYYY-MM-DD'),
74
- (0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
75
- ]; }));
76
- today = (0, moment_1.default)();
77
- for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
78
- dateStr = period_1[_i];
79
- date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
80
- if (!date.isValid())
81
- continue;
82
- current = currentPricing[dateStr];
83
- base = (_c = basePriceMap[dateStr]) !== null && _c !== void 0 ? _c : current;
84
- if (!(dateStr in basePriceMap)) {
85
- basePriceMap[dateStr] = base;
86
- }
87
- baseForToday = basePriceMap[dateStr];
88
- leadTimeDays = date.diff(today, 'days');
89
- isAffectedHoliday = holidayDateSet.has(dateStr);
90
- if (dynamicPricing.isActive && isAffectedHoliday) {
91
- bookingIncrement = 1.05;
92
- leadTimeMultiplier = leadTimeDays >= 60 ? 1.0 : 1 + (60 - leadTimeDays) * 0.005;
93
- rawPrice = baseForToday * bookingIncrement * leadTimeMultiplier;
94
- rawPrice = Math.min(rawPrice, baseForToday + 70, baseForToday * 1.45);
95
- resultPricing[dateStr] = Math.round(rawPrice);
96
- }
97
- else {
98
- resultPricing[dateStr] = base;
99
- }
100
- }
101
- return [2 /*return*/, {
102
- updatedPricing: resultPricing,
103
- updatedBasePriceMap: basePriceMap,
104
- }];
56
+ var basePriceMap, updatedPricing, affectedDates, _i, _c, dateStr, manualPrice, basePrice, isAffected, isManuallyOverridden, increased;
57
+ var _d;
58
+ var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
59
+ return __generator(this, function (_e) {
60
+ basePriceMap = __assign({}, existingBasePriceMap);
61
+ updatedPricing = {};
62
+ affectedDates = new Set((company.holidays || [])
63
+ .filter(function (h) { return h.enableDynamicPricing; })
64
+ .flatMap(function (h) { return [
65
+ (0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
66
+ (0, moment_1.default)(h.date).format('YYYY-MM-DD'),
67
+ (0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
68
+ ]; }));
69
+ for (_i = 0, _c = Object.keys(currentPricing); _i < _c.length; _i++) {
70
+ dateStr = _c[_i];
71
+ manualPrice = currentPricing[dateStr];
72
+ basePrice = (_d = basePriceMap[dateStr]) !== null && _d !== void 0 ? _d : manualPrice;
73
+ isAffected = affectedDates.has(dateStr);
74
+ isManuallyOverridden = manualPrice !== basePrice;
75
+ if (!(dateStr in basePriceMap)) {
76
+ basePriceMap[dateStr] = manualPrice;
77
+ }
78
+ if (!isAffected || isManuallyOverridden) {
79
+ updatedPricing[dateStr] = manualPrice;
80
+ continue;
81
+ }
82
+ if (dynamicPricing.isActive) {
83
+ increased = basePrice + (dynamicPricing.amount || Math.round(basePrice * 0.05));
84
+ updatedPricing[dateStr] = Math.round(Math.min(increased, basePrice + 70));
85
+ }
86
+ else {
87
+ updatedPricing[dateStr] = basePrice;
88
+ }
105
89
  }
90
+ return [2 /*return*/, {
91
+ updatedPricing: updatedPricing,
92
+ updatedBasePriceMap: basePriceMap,
93
+ }];
106
94
  });
107
95
  }); };
108
96
  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,EAkB7C;;;QAjBC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,oBAAoB,0BAAA,EACpB,OAAO,aAAA,EACP,UAAU,gBAAA,EACV,SA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OAAO,IAAI,YAAY,CAAC,EAAE,CAAC;gBAC/B,YAAY,CAAC,OAAO,CAAC,GAAG,WAAW,CAAA;YACrC,CAAC;YAED,IAAI,CAAC,UAAU,IAAI,oBAAoB,EAAE,CAAC;gBACxC,cAAc,CAAC,OAAO,CAAC,GAAG,WAAW,CAAA;gBACrC,SAAQ;YACV,CAAC;YAED,IAAI,cAAc,CAAC,QAAQ,EAAE,CAAC;gBACtB,SAAS,GAAG,SAAS,GAAG,CAAC,cAAc,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,CAAA;gBACrF,cAAc,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,EAAE,CAAC,CAAC,CAAA;YAC3E,CAAC;iBAAM,CAAC;gBACN,cAAc,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA;YACrC,CAAC;QACH,CAAC;QAED,sBAAO;gBACL,cAAc,gBAAA;gBACd,mBAAmB,EAAE,YAAY;aAClC,EAAA;;KACF,CAAA;AA3DY,QAAA,uBAAuB,2BA2DnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper.software/common-helpers",
3
- "version": "2.2.48",
3
+ "version": "2.2.49",
4
4
  "author": "Raul Tomescu <tomescu.raul+hyper@gmail.com>",
5
5
  "description": "Hyper Software Common Javascript Helpers",
6
6
  "main": "lib/index.js",