@odynn/awayz-hotels 0.2.5 → 0.2.7
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,47 +1,47 @@
|
|
|
1
1
|
import { HotelChains as N } from "../../definitions/HotelChains.js";
|
|
2
|
-
import { EHotelSortOption as
|
|
3
|
-
const
|
|
4
|
-
var
|
|
2
|
+
import { EHotelSortOption as a, ESortingOrder as l } from "./useHotelSort.types.js";
|
|
3
|
+
const S = (r) => {
|
|
4
|
+
var n;
|
|
5
5
|
return Math.round(
|
|
6
|
-
((
|
|
6
|
+
((n = r.cashBookingOffers) == null ? void 0 : n.cheapestRateTotalAmount) || r.cashValue.amount
|
|
7
7
|
);
|
|
8
|
-
},
|
|
9
|
-
const u =
|
|
10
|
-
return u <= 0 ? 1 :
|
|
11
|
-
},
|
|
12
|
-
const u =
|
|
13
|
-
return u && !
|
|
14
|
-
},
|
|
15
|
-
const u =
|
|
16
|
-
return
|
|
17
|
-
},
|
|
18
|
-
if (!
|
|
8
|
+
}, g = (r, t, n) => {
|
|
9
|
+
const u = S(r), e = S(t);
|
|
10
|
+
return u <= 0 ? 1 : n === l.DESCENDING ? e - u : u - e;
|
|
11
|
+
}, E = (r, t, n) => {
|
|
12
|
+
const u = r.hotelGroup == "other", e = t.hotelGroup == "other", p = r.chainRating != null, c = t.chainRating != null;
|
|
13
|
+
return !p && c ? 1 : p && !c ? -1 : u && !e ? 1 : !u && e ? -1 : n === l.DESCENDING ? t.chainRating - r.chainRating : r.chainRating - t.chainRating;
|
|
14
|
+
}, I = (r, t, n) => n === l.DESCENDING ? t.distance - r.distance : r.distance - t.distance, O = (r, t, n) => {
|
|
15
|
+
const u = r.points <= 0 ? Number.MAX_VALUE : r.points, e = t.points <= 0 ? Number.MAX_VALUE : t.points;
|
|
16
|
+
return n === l.DESCENDING ? e * t.hotelProgram.valueCent - u * r.hotelProgram.valueCent : u * r.hotelProgram.valueCent - e * t.hotelProgram.valueCent;
|
|
17
|
+
}, d = (r, t, n) => r.chainRating !== t.chainRating ? E(r, t, n) : I(r, t, l.ASCENDING), j = (r) => {
|
|
18
|
+
if (!r.hotelData)
|
|
19
19
|
throw new Error("hotelData is required");
|
|
20
|
-
if (!
|
|
20
|
+
if (!r.orderBy)
|
|
21
21
|
throw new Error("orderBy is required");
|
|
22
|
-
if (!
|
|
22
|
+
if (!r.sortOrder)
|
|
23
23
|
throw new Error("sortOrder is required");
|
|
24
|
-
if (!Object.values(
|
|
24
|
+
if (!Object.values(a).includes(r.orderBy))
|
|
25
25
|
throw new Error(
|
|
26
|
-
`Invalid orderBy: ${
|
|
27
|
-
|
|
26
|
+
`Invalid orderBy: ${r.orderBy}. Please use one of the following: ${Object.values(
|
|
27
|
+
a
|
|
28
28
|
).join(", ")}`
|
|
29
29
|
);
|
|
30
|
-
if (!Object.values(
|
|
30
|
+
if (!Object.values(l).includes(r.sortOrder))
|
|
31
31
|
throw new Error(
|
|
32
|
-
`Invalid sortOrder: ${
|
|
32
|
+
`Invalid sortOrder: ${r.sortOrder}. Please use one of the following: ${Object.values(l).join(
|
|
33
33
|
", "
|
|
34
34
|
)}`
|
|
35
35
|
);
|
|
36
36
|
}, P = () => ({
|
|
37
37
|
sortHotelResults: ({
|
|
38
|
-
hotelData:
|
|
38
|
+
hotelData: n,
|
|
39
39
|
orderBy: u,
|
|
40
|
-
sortOrder:
|
|
40
|
+
sortOrder: e
|
|
41
41
|
}) => {
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
const { chainHotels:
|
|
42
|
+
j({ hotelData: n, orderBy: u, sortOrder: e });
|
|
43
|
+
const p = () => {
|
|
44
|
+
const { chainHotels: o, nonChainHotels: h } = n.reduce(
|
|
45
45
|
(s, i) => (N.isMajorChain(i.hotelGroup) ? s.chainHotels.push(i) : s.nonChainHotels.push(i), s),
|
|
46
46
|
{
|
|
47
47
|
chainHotels: [],
|
|
@@ -50,10 +50,10 @@ const H = (n) => {
|
|
|
50
50
|
), {
|
|
51
51
|
majorChainsWithAccommodationIds: f,
|
|
52
52
|
majorChainsWithoutAccommodationIds: C
|
|
53
|
-
} =
|
|
53
|
+
} = o.reduce(
|
|
54
54
|
(s, i) => {
|
|
55
|
-
var
|
|
56
|
-
return (
|
|
55
|
+
var A;
|
|
56
|
+
return (A = i.cashBookingOffers) != null && A.accommodationId ? s.majorChainsWithAccommodationIds.push(i) : s.majorChainsWithoutAccommodationIds.push(i), s;
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
majorChainsWithAccommodationIds: [],
|
|
@@ -61,61 +61,67 @@ const H = (n) => {
|
|
|
61
61
|
}
|
|
62
62
|
);
|
|
63
63
|
f.sort(
|
|
64
|
-
(s, i) =>
|
|
64
|
+
(s, i) => d(s, i, e)
|
|
65
65
|
), C.sort(
|
|
66
|
-
(s, i) =>
|
|
66
|
+
(s, i) => d(s, i, e)
|
|
67
67
|
);
|
|
68
|
-
const { luxuryHotels:
|
|
68
|
+
const { luxuryHotels: H, otherProperties: R } = h.reduce(
|
|
69
69
|
(s, i) => (i.hotelGroup !== "other" ? s.luxuryHotels.push(i) : s.otherProperties.push(i), s),
|
|
70
70
|
{
|
|
71
71
|
luxuryHotels: [],
|
|
72
72
|
otherProperties: []
|
|
73
73
|
}
|
|
74
74
|
);
|
|
75
|
-
return
|
|
75
|
+
return H.sort((s, i) => d(s, i, e)), R.sort((s, i) => d(s, i, e)), [
|
|
76
76
|
...f,
|
|
77
77
|
// available to book on Duffel
|
|
78
78
|
...C,
|
|
79
79
|
// unavailable to book on Duffel
|
|
80
|
-
...
|
|
80
|
+
...H,
|
|
81
81
|
// luxury hotels
|
|
82
|
-
...
|
|
82
|
+
...R
|
|
83
83
|
// other properties
|
|
84
84
|
];
|
|
85
85
|
};
|
|
86
|
-
let c = [],
|
|
86
|
+
let c = [], m = [];
|
|
87
87
|
switch (u) {
|
|
88
|
-
case
|
|
89
|
-
return c =
|
|
90
|
-
(
|
|
91
|
-
), c == null ? void 0 : c.concat(
|
|
92
|
-
case
|
|
93
|
-
return c =
|
|
94
|
-
case
|
|
95
|
-
return c =
|
|
96
|
-
(
|
|
97
|
-
).sort((
|
|
98
|
-
(
|
|
99
|
-
), c == null ? void 0 : c.concat(
|
|
100
|
-
case
|
|
101
|
-
return
|
|
88
|
+
case a.CASH:
|
|
89
|
+
return c = n == null ? void 0 : n.filter((o) => o.cashValue.amount > 0).sort((o, h) => g(o, h, e)), m = n == null ? void 0 : n.filter(
|
|
90
|
+
(o) => o.cashValue.amount <= 0
|
|
91
|
+
), c == null ? void 0 : c.concat(m);
|
|
92
|
+
case a.POINTS:
|
|
93
|
+
return c = n == null ? void 0 : n.filter((o) => o.points > 0).sort((o, h) => O(o, h, e)), m = n == null ? void 0 : n.filter((o) => o.points <= 0).sort((o, h) => g(o, h, e)), c == null ? void 0 : c.concat(m);
|
|
94
|
+
case a.STAR_RATING:
|
|
95
|
+
return c = n == null ? void 0 : n.filter(
|
|
96
|
+
(o) => o.cashValue.amount > 0 || o.points > 0
|
|
97
|
+
).sort((o, h) => o.cashValue.amount <= 0 && o.points <= 0 ? 1 : o.chainRating === h.chainRating ? I(o, h, e) : E(o, h, e)), m = n == null ? void 0 : n.filter(
|
|
98
|
+
(o) => o.cashValue.amount <= 0 && o.points <= 0
|
|
99
|
+
), c == null ? void 0 : c.concat(m);
|
|
100
|
+
case a.BOOKABLE:
|
|
101
|
+
return p();
|
|
102
102
|
default:
|
|
103
|
-
return
|
|
103
|
+
return p();
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
106
|
+
hotelSortOptions: () => {
|
|
107
|
+
const n = (u) => {
|
|
108
|
+
switch (u) {
|
|
109
|
+
case a.CASH:
|
|
110
|
+
return "Cash";
|
|
111
|
+
case a.POINTS:
|
|
112
|
+
return "Points";
|
|
113
|
+
case a.STAR_RATING:
|
|
114
|
+
return "Star Rating";
|
|
115
|
+
case a.BOOKABLE:
|
|
116
|
+
return "Bookable";
|
|
117
|
+
default:
|
|
118
|
+
return "Not specified";
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
return Object.values(a).map((u) => ({
|
|
122
|
+
value: u,
|
|
123
|
+
label: n(u)
|
|
124
|
+
}));
|
|
119
125
|
}
|
|
120
126
|
});
|
|
121
127
|
export {
|
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
import { IHotelDetails } from '../../main';
|
|
2
2
|
import { EHotelSortOption, ISortHotelResultsParams } from './useHotelSort.types';
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook for sorting hotel search results based on various criteria.
|
|
5
|
+
*
|
|
6
|
+
* @returns An object containing utility functions for hotel sorting:
|
|
7
|
+
* - sortHotelResults: Sorts an array of hotel data based on specified criteria
|
|
8
|
+
* - hotelSortOptionsToString: Converts sort option enum values to readable strings
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { sortHotelResults, hotelSortOptionsToString } = useHotelSort();
|
|
13
|
+
*
|
|
14
|
+
* // Sort hotels by price
|
|
15
|
+
* const sortedHotels = sortHotelResults({
|
|
16
|
+
* hotelData: hotels,
|
|
17
|
+
* orderBy: EHotelSortOption.CASH,
|
|
18
|
+
* sortOrder: ESortOrder.ASC
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Get display name for sort option
|
|
22
|
+
* const sortOptionName = hotelSortOptionsToString(EHotelSortOption.CASH); // "Cash"
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* The `sortHotelResults` function supports multiple sorting strategies:
|
|
27
|
+
* - CASH: Sorts by cash value, placing unavailable hotels at the end
|
|
28
|
+
* - POINTS: Sorts by points value, placing unavailable hotels at the end
|
|
29
|
+
* - STAR_RATING: Sorts by chain rating and distance from city center
|
|
30
|
+
* - BOOKABLE: Uses a specialized algorithm that prioritizes:
|
|
31
|
+
* 1. Major chain hotels with accommodation IDs (bookable)
|
|
32
|
+
* 2. Major chain hotels without accommodation IDs (not bookable)
|
|
33
|
+
* 3. Luxury non-chain hotels
|
|
34
|
+
* 4. Other properties
|
|
35
|
+
*
|
|
36
|
+
* Within each category, additional tie-breakers like chain rating and
|
|
37
|
+
* distance to city center are applied based on the sort order.
|
|
38
|
+
*/
|
|
3
39
|
export declare const useHotelSort: () => {
|
|
4
40
|
sortHotelResults: ({ hotelData, orderBy, sortOrder }: ISortHotelResultsParams) => IHotelDetails[];
|
|
5
|
-
|
|
41
|
+
hotelSortOptions: () => {
|
|
42
|
+
value: EHotelSortOption;
|
|
43
|
+
label: string;
|
|
44
|
+
}[];
|
|
6
45
|
};
|
package/dist/lib/main.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { IRoom, IRate } from './services/booking/BookingService.types';
|
|
|
2
2
|
import { IHotelDetails } from './components/HotelResult/HotelResult.types';
|
|
3
3
|
import { IPointsAsCash } from './utilities/pointsAsCashUtils';
|
|
4
4
|
export { ESearchType } from './services/hotel/HotelService.types';
|
|
5
|
+
export { EHotelSortOption, ESortingOrder } from './hooks/useHotelSort/useHotelSort.types';
|
|
5
6
|
export * from './components';
|
|
6
7
|
export * from './hooks';
|
|
7
8
|
export type { IRoom, IRate, IHotelDetails, IPointsAsCash };
|
package/dist/main.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { ESearchType as r } from "./services/hotel/HotelService.types.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { EHotelSortOption as p, ESortingOrder as l } from "./hooks/useHotelSort/useHotelSort.types.js";
|
|
3
|
+
import { HotelResult as m } from "./components/HotelResult/HotelResult.js";
|
|
4
|
+
import { HotelResults as x } from "./components/HotelResults/HotelResults.js";
|
|
5
|
+
import { useHotelSearch as H } from "./hooks/useHotelSearch/useHotelSearch.js";
|
|
6
|
+
import { useLocationSearch as a } from "./hooks/useLocationSearch/useLocationSearch.js";
|
|
7
|
+
import { useHotelDetails as i } from "./hooks/useHotelDetails/useHotelDetails.js";
|
|
8
|
+
import { useHotelSort as n } from "./hooks/useHotelSort/useHotelSort.js";
|
|
8
9
|
export {
|
|
10
|
+
p as EHotelSortOption,
|
|
9
11
|
r as ESearchType,
|
|
10
|
-
l as
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
l as ESortingOrder,
|
|
13
|
+
m as HotelResult,
|
|
14
|
+
x as HotelResults,
|
|
15
|
+
i as useHotelDetails,
|
|
16
|
+
H as useHotelSearch,
|
|
17
|
+
n as useHotelSort,
|
|
18
|
+
a as useLocationSearch
|
|
16
19
|
};
|