feat(SW-1454): added hotel listing * feat(SW-1454): added hotel listing Approved-by: Fredrik Thorsson
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { generateTag, generateTagsFromSystem } from "@/utils/generateTag"
|
|
|
|
import { getHotel } from "../../hotels/query"
|
|
import { getHotelIdsByCityIdentifier } from "../../hotels/utils"
|
|
import { getHotelPageUrl } from "../hotelPage/utils"
|
|
|
|
import type { HotelData } from "@/types/hotel"
|
|
import type { System } from "@/types/requests/system"
|
|
import type { GetDestinationCityPageRefsSchema } from "@/types/trpc/routers/contentstack/destinationCityPage"
|
|
import type { Lang } from "@/constants/languages"
|
|
|
|
export function generatePageTags(
|
|
validatedData: GetDestinationCityPageRefsSchema,
|
|
lang: Lang
|
|
): string[] {
|
|
const connections = getConnections(validatedData)
|
|
return [
|
|
generateTagsFromSystem(lang, connections),
|
|
generateTag(lang, validatedData.destination_city_page.system.uid),
|
|
].flat()
|
|
}
|
|
|
|
export function getConnections({
|
|
destination_city_page,
|
|
}: GetDestinationCityPageRefsSchema) {
|
|
const connections: System["system"][] = [destination_city_page.system]
|
|
if (destination_city_page.sidepeek_content) {
|
|
destination_city_page.sidepeek_content.content.embedded_itemsConnection.edges.forEach(
|
|
({ node }) => {
|
|
connections.push(node.system)
|
|
}
|
|
)
|
|
}
|
|
|
|
return connections
|
|
}
|
|
|
|
export async function getHotelListData(
|
|
lang: Lang,
|
|
serviceToken: string,
|
|
cityIdentifier: string
|
|
) {
|
|
const hotelIds = await getHotelIdsByCityIdentifier(
|
|
cityIdentifier,
|
|
serviceToken
|
|
)
|
|
|
|
const hotels = await Promise.all(
|
|
hotelIds.map(async (hotelId) => {
|
|
const [hotelData, url] = await Promise.all([
|
|
getHotel({ hotelId, language: lang }, serviceToken),
|
|
getHotelPageUrl(lang, hotelId),
|
|
])
|
|
|
|
return hotelData ? { ...hotelData, url } : null
|
|
})
|
|
)
|
|
|
|
return hotels.filter(
|
|
(hotel): hotel is HotelData & { url: string | null } => !!hotel
|
|
)
|
|
}
|