Merged in feat/SW-1454-listing-skeletons (pull request #1301)
Feat/SW-1454 listing skeletons * feat(SW-1453): added skeleton for city listning * feat(SW-1454): added skeleton for hotel listning Approved-by: Fredrik Thorsson
This commit is contained in:
@@ -6,6 +6,7 @@ import { env } from "@/env/server"
|
||||
import * as api from "@/lib/api"
|
||||
import { toApiLang } from "@/server/utils"
|
||||
|
||||
import { getHotelPageUrl } from "../contentstack/hotelPage/utils"
|
||||
import { metrics } from "./metrics"
|
||||
import {
|
||||
citiesByCountrySchema,
|
||||
@@ -14,10 +15,12 @@ import {
|
||||
getHotelIdsSchema,
|
||||
locationsSchema,
|
||||
} from "./output"
|
||||
import { getHotel } from "./query"
|
||||
|
||||
import type { Country } from "@/types/enums/country"
|
||||
import { PointOfInterestGroupEnum } from "@/types/enums/pointOfInterest"
|
||||
import type { RequestOptionsWithOutBody } from "@/types/fetch"
|
||||
import type { HotelData } from "@/types/hotel"
|
||||
import type {
|
||||
CitiesGroupedByCountry,
|
||||
CityLocation,
|
||||
@@ -477,3 +480,29 @@ export async function getCityIdByCityIdentifier(
|
||||
|
||||
return cityId ?? null
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user