Merged in chore/remove-unused-code (pull request #2229)
Remove unused code * Remove unused scandic-web files * Remove unused exports Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
import { getHotel } from "@/lib/trpc/memoizedRequests"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
|
||||
import type {
|
||||
AlternativeHotelsAvailabilityInput,
|
||||
AvailabilityInput,
|
||||
} from "@/types/components/hotelReservation/selectHotel/availabilityInput"
|
||||
import type { NullableHotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
|
||||
import type { HotelsAvailabilityItem } from "@/types/trpc/routers/hotel/availability"
|
||||
|
||||
export async function fetchAvailableHotels(
|
||||
input: AvailabilityInput
|
||||
): Promise<NullableHotelData[]> {
|
||||
const availableHotels =
|
||||
await serverClient().hotel.availability.hotelsByCity(input)
|
||||
|
||||
if (!availableHotels) return []
|
||||
|
||||
return enhanceHotels(availableHotels)
|
||||
}
|
||||
|
||||
export async function fetchBookingCodeAvailableHotels(
|
||||
input: AvailabilityInput
|
||||
): Promise<NullableHotelData[]> {
|
||||
const availableHotels =
|
||||
await serverClient().hotel.availability.hotelsByCityWithBookingCode(input)
|
||||
|
||||
if (!availableHotels) return []
|
||||
|
||||
return enhanceHotels(availableHotels)
|
||||
}
|
||||
|
||||
export async function fetchAlternativeHotels(
|
||||
hotelId: string,
|
||||
input: AlternativeHotelsAvailabilityInput
|
||||
): Promise<NullableHotelData[]> {
|
||||
const alternativeHotelIds = await serverClient().hotel.nearbyHotelIds({
|
||||
hotelId,
|
||||
})
|
||||
|
||||
if (!alternativeHotelIds) return []
|
||||
|
||||
const availableHotels =
|
||||
await serverClient().hotel.availability.hotelsByHotelIds({
|
||||
...input,
|
||||
hotelIds: alternativeHotelIds,
|
||||
})
|
||||
|
||||
if (!availableHotels) return []
|
||||
|
||||
return enhanceHotels(availableHotels)
|
||||
}
|
||||
|
||||
async function enhanceHotels(hotels: {
|
||||
availability: HotelsAvailabilityItem[]
|
||||
}) {
|
||||
const language = getLang()
|
||||
|
||||
const hotelFetchers = hotels.availability.map(async (hotel) => {
|
||||
const hotelData = await getHotel({
|
||||
hotelId: hotel.hotelId.toString(),
|
||||
isCardOnlyPayment: false,
|
||||
language,
|
||||
})
|
||||
|
||||
if (!hotelData) return { hotelData: null, price: hotel.productType }
|
||||
|
||||
return {
|
||||
hotelData: hotelData.hotel,
|
||||
price: hotel.productType,
|
||||
}
|
||||
})
|
||||
|
||||
return await Promise.all(hotelFetchers)
|
||||
}
|
||||
Reference in New Issue
Block a user