@hyper.software/common-helpers 1.1.27 → 1.2.2
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/interfaces.d.ts +23 -0
- package/lib/services/bookingService/bookingsService.d.ts +10 -3
- package/lib/services/bookingService/bookingsService.js +51 -30
- package/lib/services/bookingService/bookingsService.js.map +1 -1
- package/lib/services/bookingService/bookingsService.test.d.ts +1 -0
- package/lib/services/bookingService/bookingsService.test.js +11281 -0
- package/lib/services/bookingService/bookingsService.test.js.map +1 -0
- package/lib/services/roomBookingServices/index.d.ts +5 -0
- package/lib/services/roomBookingServices/index.js +96 -0
- package/lib/services/roomBookingServices/index.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getChildrenCost = exports.getDiscountOrIncreaseAmount = exports.getLengthOfStayRoomBooking = exports.getBreakfastCost = void 0;
|
|
30
|
+
var moment_1 = __importDefault(require("moment"));
|
|
31
|
+
var interfaces_1 = require("../../interfaces");
|
|
32
|
+
var dateService_1 = require("../dateService/dateService");
|
|
33
|
+
var bookingsService_1 = require("../bookingService/bookingsService");
|
|
34
|
+
var dateService = __importStar(require("../dateService/dateService"));
|
|
35
|
+
var getBreakfastCost = function (roomBooking) {
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
if (!(roomBooking === null || roomBooking === void 0 ? void 0 : roomBooking.breakfastIncluded)) {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
var lengthOfStay = (0, exports.getLengthOfStayRoomBooking)(roomBooking);
|
|
41
|
+
var breakfastCost = ((_c = (_b = (_a = roomBooking === null || roomBooking === void 0 ? void 0 : roomBooking.room) === null || _a === void 0 ? void 0 : _a.roomType) === null || _b === void 0 ? void 0 : _b.breakfastInformation) === null || _c === void 0 ? void 0 : _c.cost) || 0;
|
|
42
|
+
var numberOfPersons = (roomBooking.numberOfAdults || 0) + (roomBooking.numberOfChildren || 0);
|
|
43
|
+
return breakfastCost * numberOfPersons * lengthOfStay;
|
|
44
|
+
};
|
|
45
|
+
exports.getBreakfastCost = getBreakfastCost;
|
|
46
|
+
var getLengthOfStayRoomBooking = function (roomBooking) {
|
|
47
|
+
if (!(roomBooking === null || roomBooking === void 0 ? void 0 : roomBooking.checkinDate) || !(roomBooking === null || roomBooking === void 0 ? void 0 : roomBooking.checkoutDate)) {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
return (0, moment_1.default)((0, dateService_1.normalizeDate)(roomBooking.checkoutDate)).diff((0, moment_1.default)((0, dateService_1.normalizeDate)(roomBooking.checkinDate)), 'days');
|
|
51
|
+
};
|
|
52
|
+
exports.getLengthOfStayRoomBooking = getLengthOfStayRoomBooking;
|
|
53
|
+
var getDiscountOrIncreaseAmount = function (roomBooking, bookingSource) {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
var applicablePricingRules = (0, bookingsService_1.getApplicablePricingRules)(roomBooking, bookingSource);
|
|
56
|
+
var sortedRules = applicablePricingRules.sort(function (a, b) { return a.numberOfAdults - b.numberOfAdults; });
|
|
57
|
+
var discountOrIncrease = sortedRules.find(function (rule) { return rule.active && rule.numberOfAdults >= roomBooking.numberOfAdults; });
|
|
58
|
+
if (!discountOrIncrease) {
|
|
59
|
+
discountOrIncrease = sortedRules[sortedRules.length - 1];
|
|
60
|
+
}
|
|
61
|
+
if (!discountOrIncrease || discountOrIncrease.value === undefined) {
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
var checkinDate = (0, moment_1.default)(dateService.normalizeDate(roomBooking.checkinDate));
|
|
65
|
+
var checkoutDate = (0, moment_1.default)(dateService.normalizeDate(roomBooking.checkoutDate));
|
|
66
|
+
var basePrice = (0, bookingsService_1.getBaseAccommodationCost)([roomBooking], checkinDate, checkoutDate, bookingSource) /
|
|
67
|
+
(0, exports.getLengthOfStayRoomBooking)(roomBooking);
|
|
68
|
+
if (basePrice === 0)
|
|
69
|
+
return roomBooking.pricePerNight || 0;
|
|
70
|
+
var discountAmount = discountOrIncrease.type === interfaces_1.DISCOUNT_TYPE.PERCENTAGE
|
|
71
|
+
? basePrice * (discountOrIncrease.value / 100)
|
|
72
|
+
: discountOrIncrease.value;
|
|
73
|
+
var isDiscount = roomBooking.numberOfAdults < ((_b = (_a = roomBooking.room) === null || _a === void 0 ? void 0 : _a.roomType) === null || _b === void 0 ? void 0 : _b.maxNumberOfAdults);
|
|
74
|
+
return isDiscount ? -discountAmount : discountAmount;
|
|
75
|
+
};
|
|
76
|
+
exports.getDiscountOrIncreaseAmount = getDiscountOrIncreaseAmount;
|
|
77
|
+
var getChildrenCost = function (roomBooking) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
if (!((_b = (_a = roomBooking.room) === null || _a === void 0 ? void 0 : _a.roomType) === null || _b === void 0 ? void 0 : _b.childrenRates) || !roomBooking.numberOfChildren || roomBooking.numberOfChildren === 0) {
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
var roomType = roomBooking.room.roomType;
|
|
83
|
+
var childrenRates = roomType.childrenRates;
|
|
84
|
+
var numberOfNights = (0, exports.getLengthOfStayRoomBooking)(roomBooking);
|
|
85
|
+
var childrenAges = roomType.childrenAges || [];
|
|
86
|
+
return childrenAges.reduce(function (total, child) {
|
|
87
|
+
var _a;
|
|
88
|
+
if (child.age !== null && child.age !== undefined) {
|
|
89
|
+
var rate = ((_a = childrenRates.find(function (rate) { return child.age >= rate.minChildAge && child.age <= rate.maxChildAge; })) === null || _a === void 0 ? void 0 : _a.value) || 0;
|
|
90
|
+
return total + rate * numberOfNights;
|
|
91
|
+
}
|
|
92
|
+
return total;
|
|
93
|
+
}, 0);
|
|
94
|
+
};
|
|
95
|
+
exports.getChildrenCost = getChildrenCost;
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/roomBookingServices/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAC3B,+CAAyG;AACzG,0DAA0D;AAC1D,qEAAuG;AACvG,sEAAyD;AAElD,IAAM,gBAAgB,GAAG,UAAC,WAAyB;;IACxD,IAAI,CAAC,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,iBAAiB,CAAA,EAAE,CAAC;QACpC,OAAO,CAAC,CAAA;IACV,CAAC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"Hyper Software Common Javascript Helpers",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@babel/preset-env": "^7.23.3",
|
|
38
|
-
"@hyper.software/common-models": "^2.
|
|
38
|
+
"@hyper.software/common-models": "^2.3.4",
|
|
39
39
|
"@hyper.software/tslint-config": "^1.0.1",
|
|
40
40
|
"@sentry/types": "^7.77.0",
|
|
41
41
|
"@types/cookie": "^0.5.3",
|