Merged in feat/SW-2033-implement-new-room-feature-request (pull request #1665)
feat(SW-2033): Added new route for fetching room features, and merged the data with existing availability data * feat(SW-2033): Added new route for fetching room features, and merged the data with existing availability data * fix: issue with total price not including room features * fix: add return null * fix * fix * fixes from PR feedback Approved-by: Arvid Norlin
This commit is contained in:
@@ -38,6 +38,7 @@ import {
|
||||
hotelsAvailabilityInputSchema,
|
||||
nearbyHotelIdsInput,
|
||||
ratesInputSchema,
|
||||
roomFeaturesInputSchema,
|
||||
roomPackagesInputSchema,
|
||||
roomsCombinedAvailabilityInputSchema,
|
||||
selectedRoomAvailabilityInputSchema,
|
||||
@@ -51,6 +52,7 @@ import {
|
||||
hotelSchema,
|
||||
packagesSchema,
|
||||
ratesSchema,
|
||||
roomFeaturesSchema,
|
||||
roomsAvailabilitySchema,
|
||||
} from "./output"
|
||||
import tempRatesData from "./tempRatesData.json"
|
||||
@@ -917,6 +919,77 @@ export const hotelQueryRouter = router({
|
||||
.concat(unavailableHotels.availability),
|
||||
}
|
||||
}),
|
||||
roomFeatures: serviceProcedure
|
||||
.input(roomFeaturesInputSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { hotelId, startDate, endDate, adultsCount, childArray } = input
|
||||
|
||||
const responses = await Promise.allSettled(
|
||||
adultsCount.map(async (adultCount, index) => {
|
||||
const kids = childArray?.[index]
|
||||
const params = {
|
||||
hotelId,
|
||||
roomStayStartDate: startDate,
|
||||
roomStayEndDate: endDate,
|
||||
adults: adultCount,
|
||||
...(kids?.length && { children: generateChildrenString(kids) }),
|
||||
}
|
||||
|
||||
metrics.roomFeatures.counter.add(1, params)
|
||||
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.Availability.roomFeatures(hotelId),
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||
},
|
||||
},
|
||||
params
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = apiResponse.text()
|
||||
console.error(
|
||||
"api.availability.roomfeature error",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params },
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
},
|
||||
})
|
||||
)
|
||||
metrics.roomFeatures.fail.add(1, params)
|
||||
return null
|
||||
}
|
||||
|
||||
const data = await apiResponse.json()
|
||||
const validatedRoomFeaturesData = roomFeaturesSchema.safeParse(data)
|
||||
if (!validatedRoomFeaturesData.success) {
|
||||
console.error(
|
||||
"api.availability.roomfeature error",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params },
|
||||
error: validatedRoomFeaturesData.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
metrics.roomFeatures.success.add(1, params)
|
||||
|
||||
return validatedRoomFeaturesData.data
|
||||
})
|
||||
)
|
||||
|
||||
return responses.map((features) => {
|
||||
if (features.status === "fulfilled") {
|
||||
return features.value
|
||||
}
|
||||
return null
|
||||
})
|
||||
}),
|
||||
}),
|
||||
rates: router({
|
||||
get: publicProcedure.input(ratesInputSchema).query(async () => {
|
||||
|
||||
Reference in New Issue
Block a user