Merged in fix/nullcheck-gethotelpins (pull request #1296)

fix: getHotelPins - null check on hotelData

* fix: getHotelPins - null check on hotelData


Approved-by: Pontus Dreij
This commit is contained in:
Linus Flood
2025-02-10 15:11:39 +00:00
parent c863294919
commit a86f0f3993

View File

@@ -4,32 +4,34 @@ import type { HotelPin } from "@/types/components/hotelReservation/selectHotel/m
export function getHotelPins(hotels: HotelData[]): HotelPin[] { export function getHotelPins(hotels: HotelData[]): HotelPin[] {
if (hotels.length === 0) return [] if (hotels.length === 0) return []
return hotels.map((hotel) => ({ return hotels
coordinates: { .filter((hotel) => hotel.hotelData)
lat: hotel.hotelData.location.latitude, .map((hotel) => ({
lng: hotel.hotelData.location.longitude, coordinates: {
}, lat: hotel.hotelData.location.latitude,
name: hotel.hotelData.name, lng: hotel.hotelData.location.longitude,
publicPrice: hotel.price?.public?.localPrice.pricePerNight ?? null, },
memberPrice: hotel.price?.member?.localPrice.pricePerNight ?? null, name: hotel.hotelData.name,
currency: publicPrice: hotel.price?.public?.localPrice.pricePerNight ?? null,
hotel.price?.public?.localPrice.currency || memberPrice: hotel.price?.member?.localPrice.pricePerNight ?? null,
hotel.price?.member?.localPrice.currency || currency:
"N/A", hotel.price?.public?.localPrice.currency ||
images: [ hotel.price?.member?.localPrice.currency ||
hotel.hotelData.hotelContent.images, "N/A",
...(hotel.hotelData.gallery?.heroImages ?? []), images: [
], hotel.hotelData.hotelContent.images,
amenities: hotel.hotelData.detailedFacilities ...(hotel.hotelData.gallery?.heroImages ?? []),
.map((facility) => ({ ],
...facility, amenities: hotel.hotelData.detailedFacilities
icon: facility.icon ?? "None", .map((facility) => ({
})) ...facility,
.slice(0, 5), icon: facility.icon ?? "None",
ratings: hotel.hotelData.ratings?.tripAdvisor.rating ?? null, }))
operaId: hotel.hotelData.operaId, .slice(0, 5),
facilityIds: hotel.hotelData.detailedFacilities.map( ratings: hotel.hotelData.ratings?.tripAdvisor.rating ?? null,
(facility) => facility.id operaId: hotel.hotelData.operaId,
), facilityIds: hotel.hotelData.detailedFacilities.map(
})) (facility) => facility.id
),
}))
} }