@hyper.software/common-helpers 2.3.2 → 2.3.3

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.
@@ -54,14 +54,14 @@ exports.calculateDynamicPricing = void 0;
54
54
  var moment_1 = __importDefault(require("moment"));
55
55
  var dateService_1 = require("../dateService/dateService");
56
56
  var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
57
- var basePriceMap, resultPricing, period, holidayDateSet, _i, period_1, dateStr, date, current, baseForToday, isAffectedHoliday, increase, rawPrice;
57
+ var basePriceMap, resultPricing, period, affectedDatesSet, _i, period_1, dateStr, isAffected, current, date, base, increase, rawPrice;
58
58
  var _c;
59
59
  var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
60
60
  return __generator(this, function (_d) {
61
61
  basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
62
62
  resultPricing = {};
63
63
  period = Object.keys(currentPricing);
64
- holidayDateSet = new Set((company.holidays || [])
64
+ affectedDatesSet = new Set((company.holidays || [])
65
65
  .filter(function (h) { return h.enableDynamicPricing; })
66
66
  .flatMap(function (h) { return [
67
67
  (0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
@@ -71,27 +71,29 @@ var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], voi
71
71
  if (!dynamicPricing.isActive) {
72
72
  return [2 /*return*/, {
73
73
  updatedPricing: currentPricing,
74
- updatedBasePriceMap: basePriceMap,
74
+ updatedBasePriceMap: {},
75
75
  }];
76
76
  }
77
77
  for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
78
78
  dateStr = period_1[_i];
79
+ isAffected = affectedDatesSet.has(dateStr);
80
+ current = currentPricing[dateStr];
79
81
  date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
80
- if (!date.isValid())
82
+ if (!isAffected || !date.isValid()) {
83
+ resultPricing[dateStr] = current;
81
84
  continue;
82
- current = currentPricing[dateStr];
85
+ }
83
86
  if (!(dateStr in basePriceMap) && typeof current === 'number') {
84
87
  basePriceMap[dateStr] = current;
85
88
  }
86
- baseForToday = basePriceMap[dateStr];
87
- isAffectedHoliday = holidayDateSet.has(dateStr);
88
- if (!isAffectedHoliday || baseForToday == null) {
89
- resultPricing[dateStr] = baseForToday !== null && baseForToday !== void 0 ? baseForToday : current;
89
+ base = basePriceMap[dateStr];
90
+ if (base == null) {
91
+ resultPricing[dateStr] = current;
90
92
  continue;
91
93
  }
92
- increase = (_c = dynamicPricing.amount) !== null && _c !== void 0 ? _c : Math.round(baseForToday * 0.05);
94
+ increase = (_c = dynamicPricing.amount) !== null && _c !== void 0 ? _c : Math.round(base * 0.05);
93
95
  increase += 10;
94
- rawPrice = Math.min(baseForToday + increase, baseForToday + 70);
96
+ rawPrice = Math.min(base + increase, base + 70);
95
97
  resultPricing[dateStr] = Math.round(rawPrice);
96
98
  }
97
99
  return [2 /*return*/, {
@@ -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,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,GAAwC,EAAE,CAAA;QAEvD,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAEpC,cAAc,GAAG,IAAI,GAAG,CAC5B,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;aACrB,MAAM,CAAC,UAAC,CAAC,IAAK,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,cAAZ,YAAY,GAAI,OAAO,CAAA;gBAChD,SAAQ;YACV,CAAC;YAEG,QAAQ,GAAG,MAAA,cAAc,CAAC,MAAM,mCAAI,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,CAAA;YACvE,QAAQ,IAAI,EAAE,CAAA;YAER,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,GAAG,QAAQ,EAAE,YAAY,GAAG,EAAE,CAAC,CAAA;YAErE,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC/C,CAAC;QAED,sBAAO;gBACL,cAAc,EAAE,aAAa;gBAC7B,mBAAmB,EAAE,YAAY;aAClC,EAAA;;KACF,CAAA;AAlEY,QAAA,uBAAuB,2BAkEnC"}
1
+ {"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAE3B,0DAA0D;AAEnD,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,GAAwC,EAAE,CAAA;QAEvD,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;QAEpC,gBAAgB,GAAG,IAAI,GAAG,CAC9B,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;aACrB,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,oBAAoB,EAAtB,CAAsB,CAAC;aACrC,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA;YACd,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAA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,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAA;YAC/D,QAAQ,IAAI,EAAE,CAAA;YACR,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,QAAQ,EAAE,IAAI,GAAG,EAAE,CAAC,CAAA;YAErD,aAAa,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC/C,CAAC;QAED,sBAAO;gBACL,cAAc,EAAE,aAAa;gBAC7B,mBAAmB,EAAE,YAAY;aAClC,EAAA;;KACF,CAAA;AAlEY,QAAA,uBAAuB,2BAkEnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper.software/common-helpers",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "author": "Raul Tomescu <tomescu.raul+hyper@gmail.com>",
5
5
  "description": "Hyper Software Common Javascript Helpers",
6
6
  "main": "lib/index.js",