@odynn/awayz-hotels 0.3.13 → 0.3.14
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,85 +1,101 @@
|
|
|
1
|
-
import { useMemo as
|
|
2
|
-
import { HotelChains as
|
|
3
|
-
import { EHotelSortOption as
|
|
4
|
-
const
|
|
5
|
-
var
|
|
1
|
+
import { useMemo as G } from "react";
|
|
2
|
+
import { HotelChains as H } from "../../definitions/HotelChains.js";
|
|
3
|
+
import { EHotelSortOption as f, ESortingOrder as C } from "../../enums/index.js";
|
|
4
|
+
const A = (o) => {
|
|
5
|
+
var a;
|
|
6
6
|
return Math.round(
|
|
7
|
-
((
|
|
7
|
+
((a = o.cashBookingOffers) == null ? void 0 : a.cheapestRateTotalAmount) || o.cashValue.amount
|
|
8
8
|
);
|
|
9
|
-
},
|
|
10
|
-
const
|
|
11
|
-
return
|
|
12
|
-
},
|
|
13
|
-
const
|
|
14
|
-
return !c &&
|
|
15
|
-
},
|
|
16
|
-
const
|
|
17
|
-
return
|
|
18
|
-
},
|
|
19
|
-
const { chainHotels:
|
|
20
|
-
(
|
|
9
|
+
}, I = (o, t, a) => {
|
|
10
|
+
const r = A(o), e = A(t);
|
|
11
|
+
return r <= 0 ? 1 : a === C.DESCENDING ? e - r : r - e;
|
|
12
|
+
}, N = (o, t, a) => {
|
|
13
|
+
const r = o.hotelGroup == "other", e = t.hotelGroup == "other", c = o.chainRating != null, m = t.chainRating != null;
|
|
14
|
+
return !c && m ? 1 : c && !m ? -1 : r && !e ? 1 : !r && e ? -1 : a === C.DESCENDING ? t.chainRating - o.chainRating : o.chainRating - t.chainRating;
|
|
15
|
+
}, V = (o, t, a) => a === C.DESCENDING ? t.distance - o.distance : o.distance - t.distance, S = (o, t, a) => {
|
|
16
|
+
const r = o.points <= 0 ? Number.MAX_VALUE : o.points, e = t.points <= 0 ? Number.MAX_VALUE : t.points;
|
|
17
|
+
return a === C.DESCENDING ? e - r : r - e;
|
|
18
|
+
}, s = (o, t, a) => o.chainRating !== t.chainRating ? N(o, t, a) : V(o, t, C.ASCENDING), E = (o, t) => {
|
|
19
|
+
const { chainHotels: a, nonChainHotels: r } = o.reduce(
|
|
20
|
+
(n, h) => (H.isMajorChain(h.hotelGroup) ? n.chainHotels.push(h) : n.nonChainHotels.push(h), n),
|
|
21
21
|
{
|
|
22
22
|
chainHotels: [],
|
|
23
23
|
nonChainHotels: []
|
|
24
24
|
}
|
|
25
25
|
), {
|
|
26
|
-
majorChainsWithAccommodationIds:
|
|
26
|
+
majorChainsWithAccommodationIds: e,
|
|
27
27
|
majorChainsWithoutAccommodationIds: c
|
|
28
|
-
} =
|
|
29
|
-
(
|
|
30
|
-
var
|
|
31
|
-
return (
|
|
28
|
+
} = a.reduce(
|
|
29
|
+
(n, h) => {
|
|
30
|
+
var g;
|
|
31
|
+
return (g = h.cashBookingOffers) != null && g.accommodationId ? n.majorChainsWithAccommodationIds.push(h) : n.majorChainsWithoutAccommodationIds.push(h), n;
|
|
32
32
|
},
|
|
33
33
|
{
|
|
34
34
|
majorChainsWithAccommodationIds: [],
|
|
35
35
|
majorChainsWithoutAccommodationIds: []
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
|
-
|
|
39
|
-
(
|
|
38
|
+
e.sort((n, h) => s(n, h, t)), c.sort(
|
|
39
|
+
(n, h) => s(n, h, t)
|
|
40
40
|
);
|
|
41
|
-
const { luxuryHotels:
|
|
42
|
-
(
|
|
41
|
+
const { luxuryHotels: m, otherProperties: p } = r.reduce(
|
|
42
|
+
(n, h) => (h.hotelGroup !== "other" ? n.luxuryHotels.push(h) : n.otherProperties.push(h), n),
|
|
43
43
|
{
|
|
44
44
|
luxuryHotels: [],
|
|
45
45
|
otherProperties: []
|
|
46
46
|
}
|
|
47
47
|
);
|
|
48
|
-
return
|
|
49
|
-
...
|
|
48
|
+
return m.sort((n, h) => s(n, h, t)), p.sort((n, h) => s(n, h, t)), [
|
|
49
|
+
...e,
|
|
50
50
|
// available to book on Duffel
|
|
51
51
|
...c,
|
|
52
52
|
// unavailable to book on Duffel
|
|
53
|
-
...
|
|
53
|
+
...m,
|
|
54
54
|
// luxury hotels
|
|
55
|
-
...
|
|
55
|
+
...p
|
|
56
56
|
// other properties
|
|
57
57
|
];
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
orderBy:
|
|
61
|
-
sortOrder:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
case
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
58
|
+
}, D = ({
|
|
59
|
+
unsortedResults: o,
|
|
60
|
+
orderBy: t,
|
|
61
|
+
sortOrder: a,
|
|
62
|
+
splitMajorChains: r = !1
|
|
63
|
+
}) => G(() => {
|
|
64
|
+
let c = [], m = [], p = [];
|
|
65
|
+
switch (t) {
|
|
66
|
+
case f.CASH:
|
|
67
|
+
c = o == null ? void 0 : o.filter((i) => i.cashValue.amount > 0).sort((i, n) => I(i, n, a)), m = o == null ? void 0 : o.filter(
|
|
68
|
+
(i) => i.cashValue.amount <= 0
|
|
69
|
+
), p = c == null ? void 0 : c.concat(m);
|
|
70
|
+
break;
|
|
71
|
+
case f.POINTS:
|
|
72
|
+
c = o == null ? void 0 : o.filter((i) => i.points > 0).sort((i, n) => S(i, n, a)), m = o == null ? void 0 : o.filter((i) => i.points <= 0).sort((i, n) => I(i, n, a)), p = c == null ? void 0 : c.concat(m);
|
|
73
|
+
break;
|
|
74
|
+
case f.STAR_RATING:
|
|
75
|
+
c = o == null ? void 0 : o.filter(
|
|
76
|
+
(i) => i.cashValue.amount > 0 || i.points > 0
|
|
77
|
+
).sort((i, n) => i.cashValue.amount <= 0 && i.points <= 0 ? 1 : i.chainRating === n.chainRating ? V(i, n, a) : N(i, n, a)), m = o == null ? void 0 : o.filter(
|
|
78
|
+
(i) => i.cashValue.amount <= 0 && i.points <= 0
|
|
79
|
+
), p = c == null ? void 0 : c.concat(m);
|
|
80
|
+
break;
|
|
81
|
+
case f.BOOKABLE:
|
|
82
|
+
p = E(o, a);
|
|
83
|
+
break;
|
|
79
84
|
default:
|
|
80
|
-
|
|
85
|
+
p = E(o, a);
|
|
86
|
+
break;
|
|
81
87
|
}
|
|
82
|
-
|
|
88
|
+
if (r && p) {
|
|
89
|
+
const i = p.filter(
|
|
90
|
+
(h) => H.isMajorChain(h.hotelGroup)
|
|
91
|
+
), n = p.filter(
|
|
92
|
+
(h) => !H.isMajorChain(h.hotelGroup)
|
|
93
|
+
);
|
|
94
|
+
return [...i, ...n];
|
|
95
|
+
}
|
|
96
|
+
return p;
|
|
97
|
+
}, [o, t, a, r]);
|
|
83
98
|
export {
|
|
84
|
-
|
|
99
|
+
A as getCashValue,
|
|
100
|
+
D as useHotelSort
|
|
85
101
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IHotelDetails } from '../../main';
|
|
2
2
|
import { IUseHotelSortParams } from './useHotelSort.types';
|
|
3
|
+
export declare const getCashValue: (result: IHotelDetails) => number;
|
|
3
4
|
/**
|
|
4
5
|
* Custom hook for sorting hotel search results based on various criteria.
|
|
5
6
|
*
|
|
@@ -36,4 +37,4 @@ import { IUseHotelSortParams } from './useHotelSort.types';
|
|
|
36
37
|
* Within each category, additional tie-breakers like chain rating and
|
|
37
38
|
* distance to city center are applied based on the sort order.
|
|
38
39
|
*/
|
|
39
|
-
export declare const useHotelSort: ({
|
|
40
|
+
export declare const useHotelSort: ({ unsortedResults, orderBy, sortOrder, splitMajorChains }: IUseHotelSortParams) => IHotelDetails[];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { IHotelDetails } from '../../main';
|
|
2
2
|
import { EHotelSortOption, ESortingOrder } from '../../enums';
|
|
3
3
|
export interface IUseHotelSortParams {
|
|
4
|
-
|
|
4
|
+
unsortedResults: IHotelDetails[];
|
|
5
5
|
orderBy: EHotelSortOption;
|
|
6
6
|
sortOrder: ESortingOrder;
|
|
7
|
+
splitMajorChains?: boolean;
|
|
7
8
|
}
|