@hyper.software/common-helpers 2.10.38 → 2.10.40

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,9 +1,9 @@
1
- import { IDynamicPricing, IRoomTypePricePlanPricingInformation } from '../../interfaces';
2
- export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, manualPricing, enabledHolidayDates, }: {
1
+ import { ICompany, IRoomTypePricePlanPricingInformation, IDynamicPricing } from '../../interfaces';
2
+ export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing, existingBasePriceMap, company, }: {
3
3
  currentPricing: IRoomTypePricePlanPricingInformation;
4
4
  dynamicPricing: IDynamicPricing;
5
- manualPricing: IRoomTypePricePlanPricingInformation;
6
- enabledHolidayDates: string[];
5
+ existingBasePriceMap: Record<string, number>;
6
+ company: ICompany;
7
7
  }) => Promise<{
8
8
  updatedPricing: IRoomTypePricePlanPricingInformation;
9
9
  updatedBasePriceMap: Record<string, number>;
@@ -52,45 +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 interfaces_1 = require("../../interfaces");
55
+ var dateService_1 = require("../dateService/dateService");
56
56
  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;
58
- var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, manualPricing = _b.manualPricing, enabledHolidayDates = _b.enabledHolidayDates;
57
+ var basePriceMap, resultPricing, holidayDateSet, _i, _c, dateStr, date, current, base, baseForToday, increasedPrice;
58
+ var _d;
59
+ var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
59
60
  return __generator(this, function (_e) {
60
- updatedPricing = __assign({}, currentPricing);
61
- basePriceMap = __assign({}, dynamicPricing.basePrice);
62
- affectedDates = new Set();
63
- for (_i = 0, enabledHolidayDates_1 = enabledHolidayDates; _i < enabledHolidayDates_1.length; _i++) {
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'));
69
- }
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];
78
- if (manualPrice !== undefined) {
79
- updatedPricing[date] = manualPrice;
61
+ basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
62
+ resultPricing = {};
63
+ holidayDateSet = new Set((company.holidays || [])
64
+ .filter(function (h) { return h.enableDynamicPricing; })
65
+ .flatMap(function (h) { return [
66
+ (0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
67
+ (0, moment_1.default)(h.date).format('YYYY-MM-DD'),
68
+ (0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
69
+ ]; }));
70
+ for (_i = 0, _c = Object.keys(currentPricing); _i < _c.length; _i++) {
71
+ dateStr = _c[_i];
72
+ date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
73
+ if (!date.isValid())
80
74
  continue;
75
+ current = currentPricing[dateStr];
76
+ base = (_d = basePriceMap[dateStr]) !== null && _d !== void 0 ? _d : current;
77
+ if (!(dateStr in basePriceMap)) {
78
+ basePriceMap[dateStr] = base;
81
79
  }
82
- 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);
80
+ if (dynamicPricing.isActive && holidayDateSet.has(dateStr)) {
81
+ baseForToday = basePriceMap[dateStr];
82
+ increasedPrice = baseForToday;
83
+ if (dynamicPricing.amount) {
84
+ if (dynamicPricing.type === 'INCREASE') {
85
+ increasedPrice = baseForToday + dynamicPricing.amount;
86
+ }
87
+ else if (dynamicPricing.type === 'DECREASE') {
88
+ increasedPrice = Math.max(0, baseForToday - dynamicPricing.amount);
89
+ }
90
+ }
91
+ else {
92
+ increasedPrice = Math.round(baseForToday * 1.05);
93
+ }
94
+ resultPricing[dateStr] = increasedPrice;
87
95
  }
88
96
  else {
89
- updatedPricing[date] = base;
97
+ resultPricing[dateStr] = base;
90
98
  }
91
99
  }
92
100
  return [2 /*return*/, {
93
- updatedPricing: updatedPricing,
101
+ updatedPricing: resultPricing,
94
102
  updatedBasePriceMap: basePriceMap,
95
103
  }];
96
104
  });
@@ -1 +1 @@
1
- {"version":3,"file":"dynamicPricingService.js","sourceRoot":"","sources":["../../../src/services/dynamicPricingService/dynamicPricingService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAC3B,+CAA8G;AAEvG,IAAM,uBAAuB,GAAG,iEAAO,EAU7C;;QATC,cAAc,oBAAA,EACd,cAAc,oBAAA,EACd,aAAa,mBAAA,EACb,mBAAmB,yBAAA;;QAUb,cAAc,gBAA8C,cAAc,CAAE,CAAA;QAC5E,YAAY,gBAAgC,cAAc,CAAC,SAAS,CAAE,CAAA;QAEtE,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QACvC,WAAyC,EAAnB,2CAAmB,EAAnB,iCAAmB,EAAnB,IAAmB,EAAE,CAAC;YAAjC,OAAO;YACV,CAAC,GAAG,IAAA,gBAAM,EAAC,OAAO,CAAC,CAAA;YACzB,aAAa,CAAC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C,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;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,GAAyC,EAAE,CAAA;QAExD,cAAc,GAAG,IAAI,GAAG,CAC5B,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,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;YACtD,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;YACnC,IAAA,gBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;SAClD,EAJe,CAIf,CAAC,CACL,CAAA;QAED,WAAiD,EAA3B,KAAA,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EAA3B,cAA2B,EAA3B,IAA2B,EAAE,CAAC;YAA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AA;AA9DY,QAAA,uBAAuB,2BA8DnC"}
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.40",
4
4
  "author": "Raul Tomescu <tomescu.raul+hyper@gmail.com>",
5
5
  "description": "Hyper Software Common Javascript Helpers",
6
6
  "main": "lib/index.js",