@hyper.software/common-helpers 2.10.35 → 2.10.36
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.
- package/lib/services/bookingService/__tests__/bookingService.calculateDynamic.test.d.ts +1 -0
- package/lib/services/bookingService/__tests__/bookingService.calculateDynamic.test.js +232 -156
- package/lib/services/bookingService/__tests__/bookingService.calculateDynamic.test.js.map +1 -1
- package/lib/services/dynamicPricingService/dynamicPricingService.d.ts +0 -1
- package/lib/services/dynamicPricingService/dynamicPricingService.js +25 -39
- package/lib/services/dynamicPricingService/dynamicPricingService.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,157 +1,233 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
var moment_1 = __importDefault(require("moment"));
|
|
54
|
+
var dynamicPricingService_1 = require("../../dynamicPricingService/dynamicPricingService");
|
|
55
|
+
var interfaces_1 = require("../../../interfaces");
|
|
56
|
+
describe('calculateDynamicPricing', function () {
|
|
57
|
+
var today = (0, moment_1.default)().startOf('day');
|
|
58
|
+
var nearDate = today.clone().add(7, 'days').format('YYYY-MM-DD');
|
|
59
|
+
var farDate = today.clone().add(60, 'days').format('YYYY-MM-DD');
|
|
60
|
+
var basePrice = 100;
|
|
61
|
+
var baseDynamicPricing = function (overrides) {
|
|
62
|
+
if (overrides === void 0) { overrides = {}; }
|
|
63
|
+
return (__assign({ isActive: true, basePrice: {}, startDate: today.format('YYYY-MM-DD'), endDate: farDate, type: interfaces_1.DYNAMIC_PRICING_TYPE.INCREASE, amount: 20 }, overrides));
|
|
64
|
+
};
|
|
65
|
+
var mockCompany = {
|
|
66
|
+
id: 'comp1',
|
|
67
|
+
holidays: [],
|
|
68
|
+
};
|
|
69
|
+
it('returns base price when dynamic pricing is inactive', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
+
var result;
|
|
71
|
+
var _a, _b;
|
|
72
|
+
return __generator(this, function (_c) {
|
|
73
|
+
switch (_c.label) {
|
|
74
|
+
case 0: return [4 /*yield*/, (0, dynamicPricingService_1.calculateDynamicPricing)({
|
|
75
|
+
currentPricing: (_a = {}, _a[today.format('YYYY-MM-DD')] = 100, _a),
|
|
76
|
+
dynamicPricing: baseDynamicPricing({ isActive: false }),
|
|
77
|
+
existingBasePriceMap: (_b = {}, _b[today.format('YYYY-MM-DD')] = 90, _b),
|
|
78
|
+
company: mockCompany,
|
|
79
|
+
})];
|
|
80
|
+
case 1:
|
|
81
|
+
result = _c.sent();
|
|
82
|
+
expect(result.updatedPricing[today.format('YYYY-MM-DD')]).toBe(90);
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}); });
|
|
87
|
+
it('applies holiday dynamic pricing if date is near holiday', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
88
|
+
var holidayDate, companyWithHoliday, pricing, result;
|
|
89
|
+
var _a;
|
|
90
|
+
return __generator(this, function (_b) {
|
|
91
|
+
switch (_b.label) {
|
|
92
|
+
case 0:
|
|
93
|
+
holidayDate = (0, moment_1.default)(today).add(1, 'day').format('YYYY-MM-DD');
|
|
94
|
+
companyWithHoliday = {
|
|
95
|
+
id: 'comp1',
|
|
96
|
+
holidays: [{ date: holidayDate, enableDynamicPricing: true }],
|
|
97
|
+
};
|
|
98
|
+
pricing = (_a = {},
|
|
99
|
+
_a[holidayDate] = 100,
|
|
100
|
+
_a);
|
|
101
|
+
return [4 /*yield*/, (0, dynamicPricingService_1.calculateDynamicPricing)({
|
|
102
|
+
currentPricing: pricing,
|
|
103
|
+
dynamicPricing: baseDynamicPricing(),
|
|
104
|
+
existingBasePriceMap: {},
|
|
105
|
+
company: companyWithHoliday,
|
|
106
|
+
})];
|
|
107
|
+
case 1:
|
|
108
|
+
result = _b.sent();
|
|
109
|
+
expect(result.updatedPricing[holidayDate]).toBeGreaterThan(100);
|
|
110
|
+
return [2 /*return*/];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}); });
|
|
114
|
+
it('uses fallback pricing if base price exists and dynamic pricing is off', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
115
|
+
var result;
|
|
116
|
+
var _a, _b;
|
|
117
|
+
return __generator(this, function (_c) {
|
|
118
|
+
switch (_c.label) {
|
|
119
|
+
case 0: return [4 /*yield*/, (0, dynamicPricingService_1.calculateDynamicPricing)({
|
|
120
|
+
currentPricing: (_a = {}, _a[today.format('YYYY-MM-DD')] = 100, _a),
|
|
121
|
+
dynamicPricing: baseDynamicPricing({ isActive: false }),
|
|
122
|
+
existingBasePriceMap: (_b = {}, _b[today.format('YYYY-MM-DD')] = 95, _b),
|
|
123
|
+
company: mockCompany,
|
|
124
|
+
})];
|
|
125
|
+
case 1:
|
|
126
|
+
result = _c.sent();
|
|
127
|
+
expect(result.updatedPricing[today.format('YYYY-MM-DD')]).toBe(95);
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}); });
|
|
132
|
+
it('keeps price near base when availability is 100% and date is far', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
+
var result, price;
|
|
134
|
+
var _a;
|
|
135
|
+
return __generator(this, function (_b) {
|
|
136
|
+
switch (_b.label) {
|
|
137
|
+
case 0: return [4 /*yield*/, (0, dynamicPricingService_1.calculateDynamicPricing)({
|
|
138
|
+
currentPricing: (_a = {}, _a[farDate] = basePrice, _a),
|
|
139
|
+
dynamicPricing: baseDynamicPricing(),
|
|
140
|
+
existingBasePriceMap: {},
|
|
141
|
+
company: mockCompany,
|
|
142
|
+
})];
|
|
143
|
+
case 1:
|
|
144
|
+
result = _b.sent();
|
|
145
|
+
price = result.updatedPricing[farDate];
|
|
146
|
+
expect(price).toBeGreaterThanOrEqual(basePrice);
|
|
147
|
+
expect(price).toBeLessThanOrEqual(Math.round(basePrice * 1.1));
|
|
148
|
+
return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}); });
|
|
152
|
+
it('increases price moderately with 50% availability and date is far', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
153
|
+
var result, price;
|
|
154
|
+
var _a;
|
|
155
|
+
return __generator(this, function (_b) {
|
|
156
|
+
switch (_b.label) {
|
|
157
|
+
case 0: return [4 /*yield*/, (0, dynamicPricingService_1.calculateDynamicPricing)({
|
|
158
|
+
currentPricing: (_a = {}, _a[farDate] = basePrice, _a),
|
|
159
|
+
dynamicPricing: baseDynamicPricing(),
|
|
160
|
+
existingBasePriceMap: {},
|
|
161
|
+
company: mockCompany,
|
|
162
|
+
})];
|
|
163
|
+
case 1:
|
|
164
|
+
result = _b.sent();
|
|
165
|
+
price = result.updatedPricing[farDate];
|
|
166
|
+
expect(price).toBeGreaterThanOrEqual(basePrice);
|
|
167
|
+
expect(price).toBeLessThanOrEqual(Math.round(basePrice * 1.4));
|
|
168
|
+
return [2 /*return*/];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}); });
|
|
172
|
+
it('maximizes price with 1 room left and date is far', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
173
|
+
var result, price;
|
|
174
|
+
var _a;
|
|
175
|
+
return __generator(this, function (_b) {
|
|
176
|
+
switch (_b.label) {
|
|
177
|
+
case 0: return [4 /*yield*/, (0, dynamicPricingService_1.calculateDynamicPricing)({
|
|
178
|
+
currentPricing: (_a = {}, _a[farDate] = basePrice, _a),
|
|
179
|
+
dynamicPricing: baseDynamicPricing(),
|
|
180
|
+
existingBasePriceMap: {},
|
|
181
|
+
company: mockCompany,
|
|
182
|
+
})];
|
|
183
|
+
case 1:
|
|
184
|
+
result = _b.sent();
|
|
185
|
+
price = result.updatedPricing[farDate];
|
|
186
|
+
expect(price).toBeGreaterThanOrEqual(basePrice);
|
|
187
|
+
expect(price).toBeLessThanOrEqual(Math.round(basePrice * 1.5));
|
|
188
|
+
return [2 /*return*/];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}); });
|
|
192
|
+
it('slightly increases price with 100% availability and date is near', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
193
|
+
var result, price;
|
|
194
|
+
var _a;
|
|
195
|
+
return __generator(this, function (_b) {
|
|
196
|
+
switch (_b.label) {
|
|
197
|
+
case 0: return [4 /*yield*/, (0, dynamicPricingService_1.calculateDynamicPricing)({
|
|
198
|
+
currentPricing: (_a = {}, _a[nearDate] = basePrice, _a),
|
|
199
|
+
dynamicPricing: baseDynamicPricing(),
|
|
200
|
+
existingBasePriceMap: {},
|
|
201
|
+
company: mockCompany,
|
|
202
|
+
})];
|
|
203
|
+
case 1:
|
|
204
|
+
result = _b.sent();
|
|
205
|
+
price = result.updatedPricing[nearDate];
|
|
206
|
+
expect(price).toBeGreaterThanOrEqual(basePrice);
|
|
207
|
+
expect(price).toBeLessThanOrEqual(Math.round(basePrice * 1.2));
|
|
208
|
+
return [2 /*return*/];
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}); });
|
|
212
|
+
it('strongly increases price with 50% availability and date is near', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
213
|
+
var result, price;
|
|
214
|
+
var _a;
|
|
215
|
+
return __generator(this, function (_b) {
|
|
216
|
+
switch (_b.label) {
|
|
217
|
+
case 0: return [4 /*yield*/, (0, dynamicPricingService_1.calculateDynamicPricing)({
|
|
218
|
+
currentPricing: (_a = {}, _a[nearDate] = basePrice, _a),
|
|
219
|
+
dynamicPricing: baseDynamicPricing(),
|
|
220
|
+
existingBasePriceMap: {},
|
|
221
|
+
company: mockCompany,
|
|
222
|
+
})];
|
|
223
|
+
case 1:
|
|
224
|
+
result = _b.sent();
|
|
225
|
+
price = result.updatedPricing[nearDate];
|
|
226
|
+
expect(price).toBeGreaterThanOrEqual(basePrice);
|
|
227
|
+
expect(price).toBeLessThanOrEqual(Math.round(basePrice * 1.4));
|
|
228
|
+
return [2 /*return*/];
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}); });
|
|
232
|
+
});
|
|
157
233
|
//# sourceMappingURL=bookingService.calculateDynamic.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bookingService.calculateDynamic.test.js","sourceRoot":"","sources":["../../../../src/services/bookingService/__tests__/bookingService.calculateDynamic.test.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"bookingService.calculateDynamic.test.js","sourceRoot":"","sources":["../../../../src/services/bookingService/__tests__/bookingService.calculateDynamic.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAC3B,2FAA2F;AAC3F,kDAA2H;AAE3H,QAAQ,CAAC,yBAAyB,EAAE;IAClC,IAAM,KAAK,GAAG,IAAA,gBAAM,GAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACrC,IAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;IAClE,IAAM,OAAO,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;IAClE,IAAM,SAAS,GAAG,GAAG,CAAA;IAErB,IAAM,kBAAkB,GAAG,UAAC,SAAwC;QAAxC,0BAAA,EAAA,cAAwC;QAAsB,OAAA,YACxF,QAAQ,E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AC,QAAQ,IAAG,SAAS,KAAE;wBACzC,cAAc,EAAE,kBAAkB,EAAE;wBACpC,oBAAoB,EAAE,EAAE;wBACxB,OAAO,EAAE,WAAW;qBACrB,CAAC,EAAA;;oBALI,MAAM,GAAG,SAKb;oBAEI,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;oBAC7C,MAAM,CAAC,KAAK,CAAC,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAA;oBAC/C,MAAM,CAAC,KAAK,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAA;;;;SAC/D,CAAC,CAAA;IAEF,EAAE,CAAC,iEAAiE,EAAE;;;;;wBACrD,qBAAM,IAAA,+CAAuB,EAAC;wBAC3C,cAAc,YAAI,GAAC,QAAQ,IAAG,SAAS,KAAE;wBACzC,cAAc,EAAE,kBAAkB,EAAE;wBACpC,oBAAoB,EAAE,EAAE;wBACxB,OAAO,EAAE,WAAW;qBACrB,CAAC,EAAA;;oBALI,MAAM,GAAG,SAKb;oBAEI,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAA;oBAC7C,MAAM,CAAC,KAAK,CAAC,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAA;oBAC/C,MAAM,CAAC,KAAK,CAAC,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,CAAA;;;;SAC/D,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -8,4 +8,3 @@ export declare const calculateDynamicPricing: ({ currentPricing, dynamicPricing,
|
|
|
8
8
|
updatedPricing: IRoomTypePricePlanPricingInformation;
|
|
9
9
|
updatedBasePriceMap: Record<string, number>;
|
|
10
10
|
}>;
|
|
11
|
-
export declare const getSimpleDynamicMultiplier: (isNearFuture: boolean) => number;
|
|
@@ -50,50 +50,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.
|
|
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,
|
|
58
|
-
var
|
|
56
|
+
var basePriceMap, resultPricing, affectedDates, _i, _c, holiday, date, _d, _e, dateStr, base, isAffected;
|
|
57
|
+
var _f;
|
|
59
58
|
var currentPricing = _b.currentPricing, dynamicPricing = _b.dynamicPricing, existingBasePriceMap = _b.existingBasePriceMap, company = _b.company;
|
|
60
|
-
return __generator(this, function (
|
|
59
|
+
return __generator(this, function (_g) {
|
|
61
60
|
basePriceMap = __assign(__assign({}, dynamicPricing.basePrice), existingBasePriceMap);
|
|
62
61
|
resultPricing = {};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
(0, moment_1.default)(h.date).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
68
|
-
(0, moment_1.default)(h.date).format('YYYY-MM-DD'),
|
|
69
|
-
(0, moment_1.default)(h.date).add(1, 'day').format('YYYY-MM-DD'),
|
|
70
|
-
]; }));
|
|
71
|
-
today = (0, moment_1.default)();
|
|
72
|
-
for (_i = 0, period_1 = period; _i < period_1.length; _i++) {
|
|
73
|
-
dateStr = period_1[_i];
|
|
74
|
-
date = (0, moment_1.default)((0, dateService_1.normalizeDate)(dateStr));
|
|
75
|
-
if (!date.isValid())
|
|
62
|
+
affectedDates = new Set();
|
|
63
|
+
for (_i = 0, _c = company.holidays || []; _i < _c.length; _i++) {
|
|
64
|
+
holiday = _c[_i];
|
|
65
|
+
if (!holiday.enableDynamicPricing)
|
|
76
66
|
continue;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
resultPricing[dateStr] = Math.round(
|
|
67
|
+
date = (0, moment_1.default)(holiday.date);
|
|
68
|
+
affectedDates.add(date.clone().subtract(1, 'day').format('YYYY-MM-DD'));
|
|
69
|
+
affectedDates.add(date.format('YYYY-MM-DD'));
|
|
70
|
+
affectedDates.add(date.clone().add(1, 'day').format('YYYY-MM-DD'));
|
|
71
|
+
}
|
|
72
|
+
for (_d = 0, _e = Object.keys(currentPricing); _d < _e.length; _d++) {
|
|
73
|
+
dateStr = _e[_d];
|
|
74
|
+
base = (_f = basePriceMap[dateStr]) !== null && _f !== void 0 ? _f : currentPricing[dateStr];
|
|
75
|
+
if (!(dateStr in basePriceMap)) {
|
|
76
|
+
basePriceMap[dateStr] = base;
|
|
77
|
+
}
|
|
78
|
+
isAffected = affectedDates.has(dateStr);
|
|
79
|
+
if (dynamicPricing.isActive && isAffected) {
|
|
80
|
+
resultPricing[dateStr] = Math.round(base * 1.2);
|
|
91
81
|
}
|
|
92
|
-
else if (!dynamicPricing.isActive &&
|
|
93
|
-
resultPricing[dateStr] =
|
|
82
|
+
else if (!dynamicPricing.isActive && base !== undefined) {
|
|
83
|
+
resultPricing[dateStr] = base;
|
|
94
84
|
}
|
|
95
85
|
else {
|
|
96
|
-
resultPricing[dateStr] =
|
|
86
|
+
resultPricing[dateStr] = currentPricing[dateStr];
|
|
97
87
|
}
|
|
98
88
|
}
|
|
99
89
|
return [2 /*return*/, {
|
|
@@ -103,8 +93,4 @@ var calculateDynamicPricing = function (_a) { return __awaiter(void 0, [_a], voi
|
|
|
103
93
|
});
|
|
104
94
|
}); };
|
|
105
95
|
exports.calculateDynamicPricing = calculateDynamicPricing;
|
|
106
|
-
var getSimpleDynamicMultiplier = function (isNearFuture) {
|
|
107
|
-
return isNearFuture ? 1.2 : 1.1;
|
|
108
|
-
};
|
|
109
|
-
exports.getSimpleDynamicMultiplier = getSimpleDynamicMultiplier;
|
|
110
96
|
//# sourceMappingURL=dynamicPricingService.js.map
|
|
@@ -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;AAGpB,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,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QAEvC,WAA4C,EAAtB,KAAA,OAAO,CAAC,QAAQ,IAAI,EAAE,EAAtB,cAAsB,EAAtB,IAAsB,EAAE,CAAC;YAApC,OAAO;YAChB,IAAI,CAAC,OAAO,CAAC,oBAAoB;gBAAE,SAAQ;YAErC,IAAI,GAAG,IAAA,gBAAM,EAAC,OAAO,CAAC,IAAI,CAAC,CAAA;YACjC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;YACvE,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAA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