@hyper.software/common-helpers 2.10.38 → 2.10.39

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,4 +1,4 @@
1
- import { IDynamicPricing, IRoomTypePricePlanPricingInformation } from '../../interfaces';
1
+ import { IRoomTypePricePlanPricingInformation, IDynamicPricing } from '../../interfaces';
2
2
  export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, manualPricing, enabledHolidayDates, }: {
3
3
  currentPricing: IRoomTypePricePlanPricingInformation;
4
4
  dynamicPricing: IDynamicPricing;
@@ -52,41 +52,40 @@ 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 interfaces_1 = require("../../interfaces");
56
55
  var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var updatedPricing, basePriceMap, affectedDates, _i, enabledHolidayDates_1, holiday, m, _c, _d, date, manualPrice, current, base, multiplier;
56
+ var updatedPricing, basePriceMap, affectedDates, _i, enabledHolidayDates_1, holiday, date, _c, _d, dateStr, manualPrice, currentBase, multiplier;
57
+ var _e;
58
58
  var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, manualPricing = _b.manualPricing, enabledHolidayDates = _b.enabledHolidayDates;
59
- return __generator(this, function (_e) {
59
+ return __generator(this, function (_f) {
60
60
  updatedPricing = __assign({}, currentPricing);
61
61
  basePriceMap = __assign({}, dynamicPricing.basePrice);
62
62
  affectedDates = new Set();
63
63
  for (_i = 0, enabledHolidayDates_1 = enabledHolidayDates; _i < enabledHolidayDates_1.length; _i++) {
64
64
  holiday = enabledHolidayDates_1[_i];
65
- m = (0, moment_1.default)(holiday);
66
- affectedDates.add(m.clone().subtract(1, 'day').format('YYYY-MM-DD'));
67
- affectedDates.add(m.format('YYYY-MM-DD'));
68
- affectedDates.add(m.clone().add(1, 'day').format('YYYY-MM-DD'));
65
+ date = (0, moment_1.default)(holiday);
66
+ affectedDates.add(date.clone().subtract(1, 'day').format('YYYY-MM-DD'));
67
+ affectedDates.add(date.format('YYYY-MM-DD'));
68
+ affectedDates.add(date.clone().add(1, 'day').format('YYYY-MM-DD'));
69
69
  }
70
70
  for (_c = 0, _d = Array.from(affectedDates); _c < _d.length; _c++) {
71
- date = _d[_c];
72
- manualPrice = manualPricing[date];
73
- current = currentPricing[date];
74
- if (!(date in basePriceMap)) {
75
- basePriceMap[date] = current;
76
- }
77
- base = basePriceMap[date];
71
+ dateStr = _d[_c];
72
+ manualPrice = manualPricing[dateStr];
78
73
  if (manualPrice !== undefined) {
79
- updatedPricing[date] = manualPrice;
74
+ updatedPricing[dateStr] = manualPrice;
75
+ continue;
76
+ }
77
+ currentBase = (_e = basePriceMap[dateStr]) !== null && _e !== void 0 ? _e : currentPricing[dateStr];
78
+ if (!currentBase)
80
79
  continue;
80
+ if (!(dateStr in basePriceMap)) {
81
+ basePriceMap[dateStr] = currentBase;
81
82
  }
82
83
  if (dynamicPricing.isActive) {
83
- multiplier = dynamicPricing.type === interfaces_1.DYNAMIC_PRICING_TYPE.INCREASE
84
- ? 1 + dynamicPricing.amount / 100
85
- : 1 - dynamicPricing.amount / 100;
86
- updatedPricing[date] = Math.round(base * multiplier);
84
+ multiplier = dynamicPricing.type === 'INCREASE' ? 1 + dynamicPricing.amount / 100 : 1 - dynamicPricing.amount / 100;
85
+ updatedPricing[dateStr] = Math.round(currentBase * multiplier);
87
86
  }
88
87
  else {
89
- updatedPricing[date] = base;
88
+ updatedPricing[dateStr] = basePriceMap[dateStr];
90
89
  }
91
90
  }
92
91
  return [2 /*return*/, {
@@ -1 +1 @@
1
- {"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAC,IAAI,CAAC,GAAG,WAAW,CAAA;gBAClC,SAAQ;YACV,CAAC;YAED,IAAI,cAAc,CAAC,QAAQ,EAAE,CAAC;gBACtB,UAAU,GACd,cAAc,CAAC,IAAI,KAAK,iCAAoB,CAAC,QAAQ;oBACnD,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,GAAG,GAAG;oBACjC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,GAAG,GAAG,CAAA;gBAErC,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,UAAU,CAAC,CAAA;YACtD,CAAC;iBAAM,CAAC;gBACN,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;YAC7B,CAAC;QACH,CAAC;QAED,sBAAO;gBACL,cAAc,gBAAA;gBACd,mBAAmB,EAAE,YAAY;aAClC,EAAA;;KACF,CAAA;AAxDY,QAAA,uBAAuB,2BAwDnC"}
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,aAAa,mBAAA,EACb,mBAAmB,yBAAA;;QAUb,cAAc,gBAAQ,cAAc,CAAE,CAAA;QACtC,YAAY,gBAAgC,cAAc,CAAC,SAAS,CAAE,CAAA;QAEtE,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QAEvC,WAAyC,EAAnB,2CAAmB,EAAnB,iCAAmB,EAAnB,IAAmB,EAAE,CAAC;YAAjC,OAAO;YACV,IAAI,GAAG,IAAA,gBAAM,EAAC,OAAO,CAAC,CAAA;YAC5B,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ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;YACjD,CAAC;QACH,CAAC;QAED,sBAAO;gBACL,cAAc,gBAAA;gBACd,mBAAmB,EAAE,YAAY;aAClC,EAAA;;KACF,CAAA;AAxDY,QAAA,uBAAuB,2BAwDnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper.software/common-helpers",
3
- "version": "2.10.38",
3
+ "version": "2.10.39",
4
4
  "author": "Raul Tomescu <tomescu.raul+hyper@gmail.com>",
5
5
  "description": "Hyper Software Common Javascript Helpers",
6
6
  "main": "lib/index.js",