feat(SW-251): use availability to get hotel
This commit is contained in:
@@ -20,15 +20,6 @@ export default async function SelectHotelPage({
|
||||
setLang(params.lang)
|
||||
|
||||
const tempSearchTerm = "Stockholm"
|
||||
const getHotelFitlers = await serverClient().hotel.filters.get({
|
||||
language: params.lang,
|
||||
country: "Sweden",
|
||||
city: "Helsingborg",
|
||||
})
|
||||
|
||||
if (!getHotelFitlers) return null
|
||||
|
||||
const { filters } = getHotelFitlers
|
||||
|
||||
const getAvailableHotels = await serverClient().hotel.availability.get({
|
||||
cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54",
|
||||
@@ -56,7 +47,7 @@ export default async function SelectHotelPage({
|
||||
{intl.formatMessage({ id: "Show map" })}
|
||||
<ChevronRightIcon color="burgundy" />
|
||||
</Link>
|
||||
<HotelFilter filters={filters} />
|
||||
<HotelFilter />
|
||||
</section>
|
||||
<section className={styles.hotelCards}>
|
||||
{availability.length ? (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
import tempHotelData from "@/server/routers/hotels/tempHotelData.json"
|
||||
|
||||
import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data"
|
||||
@@ -15,6 +16,7 @@ import Caption from "@/components/TempDesignSystem/Text/Caption"
|
||||
import Footnote from "@/components/TempDesignSystem/Text/Footnote"
|
||||
import Title from "@/components/TempDesignSystem/Text/Title"
|
||||
import { getIntl } from "@/i18n"
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
|
||||
import styles from "./hotelCard.module.css"
|
||||
|
||||
@@ -31,7 +33,16 @@ export default async function HotelCard({
|
||||
// TODO: Use real endpoint.
|
||||
const hotel = tempHotelData.data.attributes
|
||||
|
||||
const sortedAmenities = hotel.detailedFacilities
|
||||
const hotelResponse = await serverClient().hotel.hotel.get({
|
||||
hotelId: hotelId.toString(),
|
||||
language: getLang(),
|
||||
})
|
||||
|
||||
if (!hotelResponse) return null
|
||||
|
||||
const { data } = hotelResponse
|
||||
|
||||
const sortedAmenities = data.attributes.detailedFacilities
|
||||
.sort((a, b) => b.sortOrder - a.sortOrder)
|
||||
.slice(0, 5)
|
||||
|
||||
@@ -39,8 +50,8 @@ export default async function HotelCard({
|
||||
<article className={styles.card}>
|
||||
<section className={styles.imageContainer}>
|
||||
<Image
|
||||
src={hotel.hotelContent.images.imageSizes.large}
|
||||
alt={hotel.hotelContent.images.metaData.altText}
|
||||
src={data.attributes.hotelContent.images.imageSizes.large}
|
||||
alt={data.attributes.hotelContent.images.metaData.altText}
|
||||
width={300}
|
||||
height={200}
|
||||
className={styles.image}
|
||||
@@ -48,7 +59,7 @@ export default async function HotelCard({
|
||||
<div className={styles.tripAdvisor}>
|
||||
<Chip intent="primary" className={styles.tripAdvisor}>
|
||||
<TripAdvisorIcon color="white" />
|
||||
{hotel.ratings?.tripAdvisor.rating}
|
||||
{data.attributes.ratings?.tripAdvisor.rating}
|
||||
</Chip>
|
||||
</div>
|
||||
</section>
|
||||
@@ -58,10 +69,10 @@ export default async function HotelCard({
|
||||
{hotel.name}
|
||||
</Title>
|
||||
<Footnote color="textMediumContrast" className={styles.adress}>
|
||||
{`${hotel.address.streetAddress}, ${hotel.address.city}`}
|
||||
{`${data.attributes.address.streetAddress}, ${data.attributes.address.city}`}
|
||||
</Footnote>
|
||||
<Footnote color="textMediumContrast">
|
||||
{`${hotel.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
|
||||
{`${data.attributes.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`}
|
||||
</Footnote>
|
||||
</section>
|
||||
<section className={styles.hotel}>
|
||||
|
||||
@@ -2,28 +2,13 @@ import { getIntl } from "@/i18n"
|
||||
|
||||
import styles from "./hotelFilter.module.css"
|
||||
|
||||
import { HotelFilterProps } from "@/types/components/hotelReservation/selectHotel/hotelFilterProps"
|
||||
|
||||
export default async function HotelFilter({ filters }: HotelFilterProps) {
|
||||
export default async function HotelFilter() {
|
||||
const { formatMessage } = await getIntl()
|
||||
|
||||
console.log(filters)
|
||||
|
||||
return (
|
||||
<aside className={styles.container}>
|
||||
<div className={styles.facilities}>
|
||||
{formatMessage({ id: "Hotel facilities" })}
|
||||
{filters.map((data) => (
|
||||
<div key={data.id}>{data.name}</div>
|
||||
))}
|
||||
</div>
|
||||
<div className={styles.facilities}>
|
||||
{/* {filters.hotelFacilities.map((hotelFilter) => (
|
||||
<div key={hotelFilter} className={styles.filter}>
|
||||
<input id={hotelFilter} name={hotelFilter} type="checkbox" />
|
||||
<label htmlFor={hotelFilter}>{hotelFilter}</label>
|
||||
</div>
|
||||
))} */}
|
||||
</div>
|
||||
<div className={styles.facilities}>
|
||||
{formatMessage({ id: "Hotel surroundings" })}
|
||||
|
||||
@@ -21,8 +21,10 @@ export const getRatesInputSchema = z.object({
|
||||
hotelId: z.string(),
|
||||
})
|
||||
|
||||
export const getFiltersInputSchema = z.object({
|
||||
export const getPlaceholderInputSchema = z.object({
|
||||
hotelId: z.string(),
|
||||
language: z.string(),
|
||||
country: z.string(),
|
||||
city: z.string(),
|
||||
include: z
|
||||
.array(z.enum(["RoomCategories", "NearbyHotels", "Restaurants", "City"]))
|
||||
.optional(),
|
||||
})
|
||||
|
||||
@@ -552,33 +552,3 @@ const rate = z.object({
|
||||
|
||||
export const getRatesSchema = z.array(rate)
|
||||
export type Rate = z.infer<typeof rate>
|
||||
|
||||
const hotelFilterSchema = z.object({
|
||||
data: z.array(
|
||||
z.object({
|
||||
attributes: z.object({
|
||||
name: z.string(),
|
||||
operaId: z.string(),
|
||||
isPublished: z.boolean(),
|
||||
cityId: z.string(),
|
||||
cityName: z.string(),
|
||||
ratings: ratingsSchema,
|
||||
address: addressSchema,
|
||||
location: locationSchema,
|
||||
hotelContent: hotelContentSchema.optional(),
|
||||
detailedFacilities: z.array(detailedFacilitySchema),
|
||||
isActive: z.boolean(),
|
||||
}),
|
||||
id: z.string(),
|
||||
language: z.unknown(),
|
||||
hotelInformationSystemId: z.number(),
|
||||
type: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export const getHotelFilterSchema = hotelFilterSchema
|
||||
export type HotelFilter = z.infer<typeof hotelFilterSchema>
|
||||
export type HotelId = HotelFilter["data"][number]["id"]
|
||||
export type HotelFilters =
|
||||
HotelFilter["data"][number]["attributes"]["detailedFacilities"]
|
||||
|
||||
@@ -27,16 +27,14 @@ import {
|
||||
} from "../contentstack/hotelPage/output"
|
||||
import {
|
||||
getAvailabilityInputSchema,
|
||||
getFiltersInputSchema,
|
||||
getHotelInputSchema,
|
||||
getPlaceholderInputSchema,
|
||||
getRatesInputSchema,
|
||||
} from "./input"
|
||||
import {
|
||||
getAvailabilitySchema,
|
||||
getHotelDataSchema,
|
||||
getHotelFilterSchema,
|
||||
getRatesSchema,
|
||||
HotelFilters,
|
||||
roomSchema,
|
||||
} from "./output"
|
||||
import tempRatesData from "./tempRatesData.json"
|
||||
@@ -423,31 +421,33 @@ export const hotelQueryRouter = router({
|
||||
return validatedHotelData.data
|
||||
}),
|
||||
}),
|
||||
filters: router({
|
||||
hotel: router({
|
||||
get: serviceProcedure
|
||||
.input(getFiltersInputSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { language, country, city } = input
|
||||
.input(getPlaceholderInputSchema)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const { hotelId, language, include } = input
|
||||
|
||||
const params: Record<string, string> = {
|
||||
hotelId,
|
||||
language,
|
||||
country,
|
||||
city,
|
||||
}
|
||||
|
||||
filterCounter.add(1, {
|
||||
if (include) {
|
||||
params.include = include.join(",")
|
||||
}
|
||||
|
||||
getHotelCounter.add(1, {
|
||||
hotelId,
|
||||
language,
|
||||
country,
|
||||
city,
|
||||
include,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.filters start",
|
||||
JSON.stringify({
|
||||
query: { params },
|
||||
})
|
||||
"api.hotels.hotel start",
|
||||
JSON.stringify({ query: { hotelId, params } })
|
||||
)
|
||||
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.hotels,
|
||||
`${api.endpoints.v1.hotels}/${hotelId}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||
@@ -458,10 +458,10 @@ export const hotelQueryRouter = router({
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
filterFailCounter.add(1, {
|
||||
getHotelFailCounter.add(1, {
|
||||
hotelId,
|
||||
language,
|
||||
country,
|
||||
city,
|
||||
include,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
@@ -470,11 +470,9 @@ export const hotelQueryRouter = router({
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.hotels.filters error",
|
||||
"api.hotels.hotel error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
params,
|
||||
},
|
||||
query: { hotelId, params },
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
@@ -486,47 +484,39 @@ export const hotelQueryRouter = router({
|
||||
}
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
const validateFilterData = getHotelFilterSchema.safeParse(apiJson)
|
||||
const validateHotelData = getHotelDataSchema.safeParse(apiJson)
|
||||
|
||||
if (!validateFilterData.success) {
|
||||
filterFailCounter.add(1, {
|
||||
if (!validateHotelData.success) {
|
||||
getHotelFailCounter.add(1, {
|
||||
hotelId,
|
||||
language,
|
||||
country,
|
||||
city,
|
||||
include,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validateFilterData.error),
|
||||
error: JSON.stringify(validateHotelData.error),
|
||||
})
|
||||
|
||||
console.error(
|
||||
"api.hotels.filters validation error",
|
||||
"api.hotels.hotel validation error",
|
||||
JSON.stringify({
|
||||
query: { params },
|
||||
error: validateFilterData.error,
|
||||
query: { hotelId, params },
|
||||
error: validateHotelData.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
|
||||
filterSuccessCounter.add(1, {
|
||||
getHotelSuccessCounter.add(1, {
|
||||
hotelId,
|
||||
language,
|
||||
country,
|
||||
city,
|
||||
include,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.fuilters success",
|
||||
JSON.stringify({ query: { params: params } })
|
||||
"api.hotels.hotel success",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params },
|
||||
})
|
||||
)
|
||||
|
||||
const hotelData = validateFilterData.data.data
|
||||
const filters = hotelData.flatMap(
|
||||
(data) => data.attributes.detailedFacilities
|
||||
)
|
||||
const unieqeFilters = [...new Set(filters.map((data) => data.id))]
|
||||
|
||||
return {
|
||||
filters: unieqeFilters
|
||||
.map((data) => filters.find((find) => find.id === data))
|
||||
.filter((filter) => filter !== undefined) as HotelFilters,
|
||||
}
|
||||
return validateHotelData.data
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { HotelFilters } from "@/server/routers/hotels/output"
|
||||
|
||||
export type HotelFilterProps = {
|
||||
filters: HotelFilters
|
||||
}
|
||||
Reference in New Issue
Block a user