refactor(SW-96): use images from API & reduce data returned in getHotel
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
publicProcedure,
|
||||
router,
|
||||
} from "@/server/trpc"
|
||||
import { extractHotelImages } from "@/server/routers/utils/hotels"
|
||||
import { toApiLang } from "@/server/utils"
|
||||
|
||||
import {
|
||||
@@ -153,6 +154,10 @@ export const hotelQueryRouter = router({
|
||||
|
||||
const included = validatedHotelData.data.included || []
|
||||
|
||||
const hotelAttributes = validatedHotelData.data.data.attributes
|
||||
|
||||
const images = extractHotelImages(hotelAttributes)
|
||||
|
||||
const roomCategories = included
|
||||
? included
|
||||
.filter((item) => item.type === "roomcategories")
|
||||
@@ -193,8 +198,14 @@ export const hotelQueryRouter = router({
|
||||
})
|
||||
)
|
||||
return {
|
||||
hotel: validatedHotelData.data.data.attributes,
|
||||
roomCategories: roomCategories,
|
||||
hotelName: hotelAttributes.name,
|
||||
hotelDescription: hotelAttributes.hotelContent.texts.descriptions.short,
|
||||
hotelLocation: hotelAttributes.location,
|
||||
hotelAddress: hotelAttributes.address,
|
||||
hotelRatings: hotelAttributes.ratings,
|
||||
hotelDetailedFacilities: hotelAttributes.detailedFacilities,
|
||||
hotelImages: images,
|
||||
roomCategories,
|
||||
}
|
||||
}),
|
||||
rates: router({
|
||||
|
||||
30
server/routers/utils/hotels.ts
Normal file
30
server/routers/utils/hotels.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { ImageItem } from "@/types/components/lightbox/lightbox"
|
||||
import { Hotel } from "@/types/hotel"
|
||||
|
||||
export function extractHotelImages(hotelData: Hotel): ImageItem[] {
|
||||
const images: ImageItem[] = []
|
||||
|
||||
if (hotelData.hotelContent?.images) {
|
||||
images.push({
|
||||
url: hotelData.hotelContent.images.imageSizes.large,
|
||||
alt: hotelData.hotelContent.images.metaData.altText,
|
||||
title:
|
||||
hotelData.hotelContent.images.metaData.title ||
|
||||
hotelData.hotelContent.images.metaData.altText,
|
||||
})
|
||||
}
|
||||
|
||||
if (hotelData.healthFacilities) {
|
||||
hotelData.healthFacilities.forEach((facility: any) => {
|
||||
facility.content.images.forEach((image: any) => {
|
||||
images.push({
|
||||
url: image.imageSizes.large,
|
||||
alt: image.metaData.altText,
|
||||
title: image.metaData.title || image.metaData.altText,
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
return images
|
||||
}
|
||||
Reference in New Issue
Block a user