feat(SW-251): set up filter route
This commit is contained in:
@@ -20,18 +20,28 @@ export default async function SelectHotelPage({
|
|||||||
setLang(params.lang)
|
setLang(params.lang)
|
||||||
|
|
||||||
const tempSearchTerm = "Stockholm"
|
const tempSearchTerm = "Stockholm"
|
||||||
const hotelFilters = await serverClient().hotel.filters.get({
|
const getHotelFitlers = await serverClient().hotel.filters.get({
|
||||||
hotelId: "879",
|
language: params.lang,
|
||||||
|
country: "Sweden",
|
||||||
|
city: "Halmstad",
|
||||||
})
|
})
|
||||||
|
|
||||||
const availableHotels = await serverClient().hotel.availability.get({
|
if (!getHotelFitlers) return null
|
||||||
|
|
||||||
|
console.log(getHotelFitlers.data)
|
||||||
|
|
||||||
|
const getAvailableHotels = await serverClient().hotel.availability.get({
|
||||||
cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54",
|
cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54",
|
||||||
roomStayStartDate: "2024-11-02",
|
roomStayStartDate: "2024-11-02",
|
||||||
roomStayEndDate: "2024-11-03",
|
roomStayEndDate: "2024-11-03",
|
||||||
adults: 1,
|
adults: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!availableHotels) return null
|
if (!getAvailableHotels) return null
|
||||||
|
|
||||||
|
const { availability } = getAvailableHotels
|
||||||
|
|
||||||
|
console.log(availability)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className={styles.main}>
|
<main className={styles.main}>
|
||||||
@@ -48,11 +58,11 @@ export default async function SelectHotelPage({
|
|||||||
{intl.formatMessage({ id: "Show map" })}
|
{intl.formatMessage({ id: "Show map" })}
|
||||||
<ChevronRightIcon color="burgundy" />
|
<ChevronRightIcon color="burgundy" />
|
||||||
</Link>
|
</Link>
|
||||||
<HotelFilter filters={hotelFilters} />
|
{/* <HotelFilter filters={hotelFilters} /> */}
|
||||||
</section>
|
</section>
|
||||||
<section className={styles.hotelCards}>
|
<section className={styles.hotelCards}>
|
||||||
{availableHotels.availability.length ? (
|
{availability.length ? (
|
||||||
availableHotels.availability.map((hotel) => (
|
availability.map((hotel) => (
|
||||||
<HotelCard
|
<HotelCard
|
||||||
key={hotel.hotelId}
|
key={hotel.hotelId}
|
||||||
checkInDate={hotel.checkInDate}
|
checkInDate={hotel.checkInDate}
|
||||||
|
|||||||
@@ -11,30 +11,30 @@ export default async function HotelFilter({ filters }: HotelFilterProps) {
|
|||||||
<aside className={styles.container}>
|
<aside className={styles.container}>
|
||||||
<div className={styles.facilities}>
|
<div className={styles.facilities}>
|
||||||
{formatMessage({ id: "Room facilities" })}
|
{formatMessage({ id: "Room facilities" })}
|
||||||
{filters.roomFacilities.map((roomFilter) => (
|
{/* {filters.roomFacilities.map((roomFilter) => (
|
||||||
<div key={roomFilter} className={styles.filter}>
|
<div key={roomFilter} className={styles.filter}>
|
||||||
<input id={roomFilter} name={roomFilter} type="checkbox" />
|
<input id={roomFilter} name={roomFilter} type="checkbox" />
|
||||||
<label htmlFor={roomFilter}>{roomFilter}</label>
|
<label htmlFor={roomFilter}>{roomFilter}</label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))} */}
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.facilities}>
|
<div className={styles.facilities}>
|
||||||
{formatMessage({ id: "Hotel facilities" })}
|
{formatMessage({ id: "Hotel facilities" })}
|
||||||
{filters.hotelFacilities.map((hotelFilter) => (
|
{/* {filters.hotelFacilities.map((hotelFilter) => (
|
||||||
<div key={hotelFilter} className={styles.filter}>
|
<div key={hotelFilter} className={styles.filter}>
|
||||||
<input id={hotelFilter} name={hotelFilter} type="checkbox" />
|
<input id={hotelFilter} name={hotelFilter} type="checkbox" />
|
||||||
<label htmlFor={hotelFilter}>{hotelFilter}</label>
|
<label htmlFor={hotelFilter}>{hotelFilter}</label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))} */}
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.facilities}>
|
<div className={styles.facilities}>
|
||||||
{formatMessage({ id: "Hotel surroundings" })}
|
{formatMessage({ id: "Hotel surroundings" })}
|
||||||
{filters.hotelSurroundings.map((surroundings) => (
|
{/* {filters.hotelSurroundings.map((surroundings) => (
|
||||||
<div key={surroundings} className={styles.filter}>
|
<div key={surroundings} className={styles.filter}>
|
||||||
<input id={surroundings} name={surroundings} type="checkbox" />
|
<input id={surroundings} name={surroundings} type="checkbox" />
|
||||||
<label htmlFor={surroundings}>{surroundings}</label>
|
<label htmlFor={surroundings}>{surroundings}</label>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))} */}
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,5 +22,7 @@ export const getRatesInputSchema = z.object({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export const getFiltersInputSchema = z.object({
|
export const getFiltersInputSchema = z.object({
|
||||||
hotelId: z.string(),
|
language: z.string(),
|
||||||
|
country: z.string(),
|
||||||
|
city: z.string(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -554,11 +554,29 @@ export const getRatesSchema = z.array(rate)
|
|||||||
|
|
||||||
export type Rate = z.infer<typeof rate>
|
export type Rate = z.infer<typeof rate>
|
||||||
|
|
||||||
const hotelFilter = z.object({
|
const hotelFilterSchema = z.object({
|
||||||
roomFacilities: z.array(z.string()),
|
data: z.array(
|
||||||
hotelFacilities: z.array(z.string()),
|
z.object({
|
||||||
hotelSurroundings: z.array(z.string()),
|
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,
|
||||||
|
detailedFacilities: z.array(detailedFacilitySchema),
|
||||||
|
isActive: z.boolean(),
|
||||||
|
}),
|
||||||
|
id: z.string(),
|
||||||
|
language: z.unknown(),
|
||||||
|
hotelInformationSystemId: z.number(),
|
||||||
|
type: z.string(),
|
||||||
|
})
|
||||||
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getFiltersSchema = hotelFilter
|
export const getHotelFilterSchema = hotelFilterSchema
|
||||||
export type HotelFilter = z.infer<typeof hotelFilter>
|
export type HotelFilter = z.infer<typeof hotelFilterSchema>
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ import {
|
|||||||
} from "./input"
|
} from "./input"
|
||||||
import {
|
import {
|
||||||
getAvailabilitySchema,
|
getAvailabilitySchema,
|
||||||
getFiltersSchema,
|
|
||||||
getHotelDataSchema,
|
getHotelDataSchema,
|
||||||
|
getHotelFilterSchema,
|
||||||
getRatesSchema,
|
getRatesSchema,
|
||||||
roomSchema,
|
roomSchema,
|
||||||
} from "./output"
|
} from "./output"
|
||||||
@@ -57,6 +57,10 @@ const availabilityFailCounter = meter.createCounter(
|
|||||||
"trpc.hotel.availability-fail"
|
"trpc.hotel.availability-fail"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const filterCounter = meter.createCounter("trcp.hotel.filter")
|
||||||
|
const filterSuccessCounter = meter.createCounter("trcp.hotel.filter-success")
|
||||||
|
const filterFailCounter = meter.createCounter("trcp.hotel.filter-fail")
|
||||||
|
|
||||||
async function getContentstackData(
|
async function getContentstackData(
|
||||||
locale: string,
|
locale: string,
|
||||||
uid: string | null | undefined
|
uid: string | null | undefined
|
||||||
@@ -420,31 +424,97 @@ export const hotelQueryRouter = router({
|
|||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
filters: router({
|
filters: router({
|
||||||
get: publicProcedure
|
get: serviceProcedure
|
||||||
.input(getFiltersInputSchema)
|
.input(getFiltersInputSchema)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
console.info("api.hotels.filters start", JSON.stringify({}))
|
const { language, country, city } = input
|
||||||
|
const params: Record<string, string> = {
|
||||||
|
language,
|
||||||
|
country,
|
||||||
|
city,
|
||||||
|
}
|
||||||
|
|
||||||
if (!tempFilterData) {
|
filterCounter.add(1, {
|
||||||
|
language,
|
||||||
|
country,
|
||||||
|
city,
|
||||||
|
})
|
||||||
|
console.info(
|
||||||
|
"api.hotels.filters start",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { params },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const apiResponse = await api.get(
|
||||||
|
api.endpoints.v1.hotels,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
params
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!apiResponse.ok) {
|
||||||
|
const text = await apiResponse.text()
|
||||||
|
filterFailCounter.add(1, {
|
||||||
|
language,
|
||||||
|
country,
|
||||||
|
city,
|
||||||
|
error_type: "http_error",
|
||||||
|
error: JSON.stringify({
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
}),
|
||||||
|
})
|
||||||
console.error(
|
console.error(
|
||||||
"api.hotels.filters error",
|
"api.hotels.filters error",
|
||||||
JSON.stringify({ error: null })
|
JSON.stringify({
|
||||||
|
query: {
|
||||||
|
params,
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
)
|
)
|
||||||
//Can't return null here since consuming component does not handle null yet
|
return null
|
||||||
// return null
|
|
||||||
}
|
}
|
||||||
const validateFilterData = getFiltersSchema.safeParse(tempFilterData)
|
|
||||||
|
const apiJson = await apiResponse.json()
|
||||||
|
const validateFilterData = getHotelFilterSchema.safeParse(apiJson)
|
||||||
|
|
||||||
if (!validateFilterData.success) {
|
if (!validateFilterData.success) {
|
||||||
|
filterFailCounter.add(1, {
|
||||||
|
language,
|
||||||
|
country,
|
||||||
|
city,
|
||||||
|
error_type: "validation_error",
|
||||||
|
error: JSON.stringify(validateFilterData.error),
|
||||||
|
})
|
||||||
console.error(
|
console.error(
|
||||||
"api.hotels.filters validation error",
|
"api.hotels.filters validation error",
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
|
query: { params },
|
||||||
error: validateFilterData.error,
|
error: validateFilterData.error,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
throw badRequestError()
|
throw badRequestError()
|
||||||
}
|
}
|
||||||
console.info("api.hotels.rates success", JSON.stringify({}))
|
|
||||||
|
filterSuccessCounter.add(1, {
|
||||||
|
language,
|
||||||
|
country,
|
||||||
|
city,
|
||||||
|
})
|
||||||
|
console.info(
|
||||||
|
"api.hotels.fuilters success",
|
||||||
|
JSON.stringify({ query: { params: params } })
|
||||||
|
)
|
||||||
return validateFilterData.data
|
return validateFilterData.data
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user