Merged in feat/SW-1457-city-dynamic-map (pull request #1320)
feat(SW-1457): Added map and fetching hotels by cityIdentifier * feat(SW-1457): Added map and fetching hotels by cityIdentifier Approved-by: Fredrik Thorsson Approved-by: Matilda Landström
This commit is contained in:
@@ -121,3 +121,7 @@ export const getAdditionalDataInputSchema = z.object({
|
||||
export const getHotelsByCountryInput = z.object({
|
||||
country: z.nativeEnum(Country),
|
||||
})
|
||||
|
||||
export const getHotelsByCityIdentifierInput = z.object({
|
||||
cityIdentifier: z.string(),
|
||||
})
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
breakfastPackageInputSchema,
|
||||
cityCoordinatesInputSchema,
|
||||
getAdditionalDataInputSchema,
|
||||
getHotelsByCityIdentifierInput,
|
||||
getHotelsByCountryInput,
|
||||
getHotelsByCSFilterInput,
|
||||
getHotelsByHotelIdsAvailabilityInputSchema,
|
||||
@@ -51,7 +52,9 @@ import {
|
||||
getCitiesByCountry,
|
||||
getCountries,
|
||||
getHotelIdsByCityId,
|
||||
getHotelIdsByCityIdentifier,
|
||||
getHotelIdsByCountry,
|
||||
getHotelsByHotelIds,
|
||||
getLocations,
|
||||
} from "./utils"
|
||||
|
||||
@@ -861,21 +864,22 @@ export const hotelQueryRouter = router({
|
||||
hotelIdsParams
|
||||
)
|
||||
|
||||
const hotels = await Promise.all(
|
||||
hotelIds.map(async (hotelId) => {
|
||||
const [hotelData, url] = await Promise.all([
|
||||
getHotel(
|
||||
{ hotelId, isCardOnlyPayment: false, language: lang },
|
||||
ctx.serviceToken
|
||||
),
|
||||
getHotelPageUrl(lang, hotelId),
|
||||
])
|
||||
return await getHotelsByHotelIds(hotelIds, lang, serviceToken)
|
||||
}),
|
||||
}),
|
||||
byCityIdentifier: router({
|
||||
get: contentStackBaseWithServiceProcedure
|
||||
.input(getHotelsByCityIdentifierInput)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const { lang, serviceToken } = ctx
|
||||
const { cityIdentifier } = input
|
||||
|
||||
return hotelData ? { ...hotelData, url } : null
|
||||
})
|
||||
const hotelIds = await getHotelIdsByCityIdentifier(
|
||||
cityIdentifier,
|
||||
serviceToken
|
||||
)
|
||||
|
||||
return hotels.filter((hotel): hotel is HotelDataWithUrl => !!hotel)
|
||||
return await getHotelsByHotelIds(hotelIds, lang, serviceToken)
|
||||
}),
|
||||
}),
|
||||
byCSFilter: router({
|
||||
|
||||
@@ -20,7 +20,7 @@ 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 { HotelDataWithUrl } from "@/types/hotel"
|
||||
import type {
|
||||
CitiesGroupedByCountry,
|
||||
CityLocation,
|
||||
@@ -423,15 +423,15 @@ export async function getHotelIdsByCityIdentifier(
|
||||
serviceToken: string
|
||||
) {
|
||||
const apiLang = toApiLang(Lang.en)
|
||||
const cityId = await getCityIdByCityIdentifier(cityIdentifier, serviceToken)
|
||||
const city = await getCityByCityIdentifier(cityIdentifier, serviceToken)
|
||||
|
||||
if (!cityId) {
|
||||
if (!city) {
|
||||
return []
|
||||
}
|
||||
|
||||
const hotelIdsParams = new URLSearchParams({
|
||||
language: apiLang,
|
||||
city: cityId,
|
||||
city: city.id,
|
||||
})
|
||||
const options: RequestOptionsWithOutBody = {
|
||||
// needs to clear default option as only
|
||||
@@ -444,11 +444,11 @@ export async function getHotelIdsByCityIdentifier(
|
||||
revalidate: env.CACHE_TIME_HOTELS,
|
||||
},
|
||||
}
|
||||
const hotelIds = await getHotelIdsByCityId(cityId, options, hotelIdsParams)
|
||||
const hotelIds = await getHotelIdsByCityId(city.id, options, hotelIdsParams)
|
||||
return hotelIds
|
||||
}
|
||||
|
||||
export async function getCityIdByCityIdentifier(
|
||||
export async function getCityByCityIdentifier(
|
||||
cityIdentifier: string,
|
||||
serviceToken: string
|
||||
) {
|
||||
@@ -473,23 +473,18 @@ export async function getCityIdByCityIdentifier(
|
||||
return null
|
||||
}
|
||||
|
||||
const cityId = locations
|
||||
const city = locations
|
||||
.filter((loc): loc is CityLocation => loc.type === "cities")
|
||||
.find((loc) => loc.cityIdentifier === cityIdentifier)?.id
|
||||
.find((loc) => loc.cityIdentifier === cityIdentifier)
|
||||
|
||||
return cityId ?? null
|
||||
return city ?? null
|
||||
}
|
||||
|
||||
export async function getHotelListData(
|
||||
export async function getHotelsByHotelIds(
|
||||
hotelIds: string[],
|
||||
lang: Lang,
|
||||
serviceToken: string,
|
||||
cityIdentifier: string
|
||||
serviceToken: string
|
||||
) {
|
||||
const hotelIds = await getHotelIdsByCityIdentifier(
|
||||
cityIdentifier,
|
||||
serviceToken
|
||||
)
|
||||
|
||||
const hotels = await Promise.all(
|
||||
hotelIds.map(async (hotelId) => {
|
||||
const [hotelData, url] = await Promise.all([
|
||||
@@ -504,7 +499,5 @@ export async function getHotelListData(
|
||||
})
|
||||
)
|
||||
|
||||
return hotels.filter(
|
||||
(hotel): hotel is HotelData & { url: string | null } => !!hotel
|
||||
)
|
||||
return hotels.filter((hotel): hotel is HotelDataWithUrl => !!hotel)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user