feat(SW-251): type assertion

This commit is contained in:
Fredrik Thorsson
2024-09-12 13:48:27 +02:00
parent 21ff8f8b5d
commit 85460e95e5
5 changed files with 29 additions and 24 deletions

View File

@@ -1,5 +1,4 @@
import { serverClient } from "@/lib/trpc/server"
import { notFound } from "@/server/errors/next"
import HotelCardListing from "@/components/HotelReservation/HotelCardListing"
import HotelFilter from "@/components/HotelReservation/SelectHotel/HotelFilter"
@@ -24,7 +23,7 @@ async function getAvailableHotels({
promotionCode,
attachedProfileId,
reservationProfileType,
}: AvailabilityInput): Promise<HotelData[] | null> {
}: AvailabilityInput): Promise<HotelData[]> {
const getAvailableHotels = await serverClient().hotel.availability.get({
cityId: cityId,
roomStayStartDate: roomStayStartDate,
@@ -36,7 +35,7 @@ async function getAvailableHotels({
reservationProfileType: reservationProfileType,
})
if (!getAvailableHotels) return null
if (!getAvailableHotels) throw new Error()
const { availability } = getAvailableHotels
@@ -46,8 +45,10 @@ async function getAvailableHotels({
language: getLang(),
})
if (!hotelData) throw new Error()
return {
hotelData: hotelData?.data.attributes,
hotelData: hotelData.data.attributes,
price: hotel.bestPricePerNight,
}
})
@@ -70,12 +71,9 @@ export default async function SelectHotelPage({
adults: 1,
})
if (!hotels) return null
if (hotels.some((item) => item?.hotelData === undefined)) return notFound()
const filters = hotels.flatMap((data) => data.hotelData.detailedFacilities)
const filters = hotels.flatMap((data) => data.hotelData?.detailedFacilities)
const filterId = [...new Set(filters.map((data) => data?.id))]
const filterId = [...new Set(filters.map((data) => data.id))]
const filterList: {
name: string
id: number
@@ -86,7 +84,7 @@ export default async function SelectHotelPage({
code?: string
iconName?: string
}[] = filterId
.map((data) => filters.find((find) => find?.id === data))
.map((data) => filters.find((find) => find.id === data))
.filter(
(
filter