Files
web/packages/trpc/lib/routers/hotels/services/getCityByCityIdentifier.ts
Joakim Jäderberg 15a2da333d Merged in feature/SW-3572-hotel-data-endpoint (pull request #3051)
SW-3572 API route for listing hotels per city or country

* wip hotel data endpoint

* Correct route params type

* wip

* skip static paths call

* timeout when getting destinations take too long

* call noStore when we get a timeout

* add cache-control headers

* .

* .

* .

* wip

* wip

* wip

* wip

* add route for getting hotels per country

* include city when listing by country

* fix distance SI unit

* fix sorting

* Merge branch 'master' of bitbucket.org:scandic-swap/web into feature/SW-3572-hotel-data-endpoint

* packages/tracking passWithNoTests

* revalidate must be static value

* remove oxc reference

* cleanup

* cleanup hotel api route

* feat(SW-3572): cleanup error handling


Approved-by: Anton Gunnarsson
2025-11-03 12:10:22 +00:00

54 lines
1.1 KiB
TypeScript

import { Lang } from "@scandic-hotels/common/constants/language"
import { isCityLocation } from "../../../types/locations"
import { getHotelIdsByCityId } from "./getHotelIdsByCityId"
import { getLocationsByCountries } from "./getLocationsByCountries"
export async function getCityByCityIdentifier({
cityIdentifier,
lang,
serviceToken,
}: {
cityIdentifier: string
lang: Lang
serviceToken: string
}) {
const locations = await getLocationsByCountries({
lang,
citiesByCountry: null,
serviceToken,
})
if (!locations || locations.length === 0) {
return null
}
const city = locations
.filter(isCityLocation)
.find((loc) => loc.cityIdentifier === cityIdentifier)
return city ?? null
}
export async function getHotelIdsByCityIdentifier(
cityIdentifier: string,
serviceToken: string
) {
const city = await getCityByCityIdentifier({
cityIdentifier,
lang: Lang.en,
serviceToken,
})
if (!city) {
return []
}
const hotelIds = await getHotelIdsByCityId({
cityId: city.id,
serviceToken,
})
return hotelIds
}