Merged in feat/SW-1090-amenities-meetings-sidepeeks (pull request #1114)
Feat/SW-1090: Sidepeek amenities and meetings Approved-by: Erik Tiekstra Approved-by: Fredrik Thorsson
This commit is contained in:
@@ -93,3 +93,8 @@ export const getCityCoordinatesInputSchema = z.object({
|
||||
address: z.string().optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
export const getMeetingRoomsInputSchema = z.object({
|
||||
hotelId: z.string(),
|
||||
language: z.string(),
|
||||
})
|
||||
|
||||
@@ -889,3 +889,49 @@ export const getHotelIdsByCityIdSchema = z
|
||||
),
|
||||
})
|
||||
.transform((data) => data.data.map((hotel) => hotel.id))
|
||||
|
||||
export const getMeetingRoomsSchema = z.object({
|
||||
data: z.array(
|
||||
z.object({
|
||||
attributes: z.object({
|
||||
name: z.string(),
|
||||
email: z.string().optional(),
|
||||
phoneNumber: z.string(),
|
||||
size: z.number(),
|
||||
doorWidth: z.number(),
|
||||
doorHeight: z.number(),
|
||||
length: z.number(),
|
||||
width: z.number(),
|
||||
height: z.number(),
|
||||
floorNumber: z.number(),
|
||||
content: z.object({
|
||||
images: z.array(imageSchema),
|
||||
texts: z.object({
|
||||
facilityInformation: z.string().optional(),
|
||||
surroundingInformation: z.string().optional(),
|
||||
descriptions: z.object({
|
||||
short: z.string().optional(),
|
||||
medium: z.string().optional(),
|
||||
}),
|
||||
meetingDescription: z
|
||||
.object({
|
||||
short: z.string().optional(),
|
||||
medium: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
}),
|
||||
seatings: z.array(
|
||||
z.object({
|
||||
type: z.string(),
|
||||
capacity: z.number(),
|
||||
})
|
||||
),
|
||||
lighting: z.string(),
|
||||
sortOrder: z.number().optional(),
|
||||
}),
|
||||
id: z.string(),
|
||||
type: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
getHotelDataInputSchema,
|
||||
getHotelsAvailabilityInputSchema,
|
||||
getHotelsInput,
|
||||
getMeetingRoomsInputSchema,
|
||||
getRatesInputSchema,
|
||||
getRoomPackagesInputSchema,
|
||||
getRoomsAvailabilityInputSchema,
|
||||
@@ -31,6 +32,7 @@ import {
|
||||
breakfastPackagesSchema,
|
||||
getHotelDataSchema,
|
||||
getHotelsAvailabilitySchema,
|
||||
getMeetingRoomsSchema,
|
||||
getRatesSchema,
|
||||
getRoomPackagesSchema,
|
||||
getRoomsAvailabilitySchema,
|
||||
@@ -51,6 +53,9 @@ import {
|
||||
hotelsAvailabilityCounter,
|
||||
hotelsAvailabilityFailCounter,
|
||||
hotelsAvailabilitySuccessCounter,
|
||||
meetingRoomsCounter,
|
||||
meetingRoomsFailCounter,
|
||||
meetingRoomsSuccessCounter,
|
||||
roomsAvailabilityCounter,
|
||||
roomsAvailabilityFailCounter,
|
||||
roomsAvailabilitySuccessCounter,
|
||||
@@ -1168,4 +1173,82 @@ export const hotelQueryRouter = router({
|
||||
return location
|
||||
}),
|
||||
}),
|
||||
meetingRooms: safeProtectedServiceProcedure
|
||||
.input(getMeetingRoomsInputSchema)
|
||||
.query(async function ({ ctx, input }) {
|
||||
const { hotelId, language } = input
|
||||
|
||||
const params: Record<string, string | string[]> = {
|
||||
hotelId,
|
||||
language,
|
||||
}
|
||||
const metricsData = { ...params, hotelId: input.hotelId }
|
||||
meetingRoomsCounter.add(1, metricsData)
|
||||
console.info(
|
||||
"api.hotels.meetingRooms start",
|
||||
JSON.stringify({ query: { hotelId, params } })
|
||||
)
|
||||
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.Hotel.Hotels.meetingRooms(input.hotelId),
|
||||
{
|
||||
cache: undefined,
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||
},
|
||||
next: {
|
||||
revalidate: TWENTYFOUR_HOURS,
|
||||
},
|
||||
},
|
||||
params
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
meetingRoomsFailCounter.add(1, {
|
||||
...metricsData,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.hotels.meetingRooms error",
|
||||
JSON.stringify({
|
||||
query: { params },
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
},
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
const validatedMeetingRooms = getMeetingRoomsSchema.safeParse(apiJson)
|
||||
|
||||
if (!validatedMeetingRooms.success) {
|
||||
console.error(
|
||||
"api.hotels.meetingRooms validation error",
|
||||
JSON.stringify({
|
||||
query: { params },
|
||||
error: validatedMeetingRooms.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
meetingRoomsSuccessCounter.add(1, {
|
||||
hotelId,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.meetingRooms success",
|
||||
JSON.stringify({ query: { params } })
|
||||
)
|
||||
|
||||
return validatedMeetingRooms.data.data
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -72,3 +72,13 @@ export const getHotelIdsSuccessCounter = meter.createCounter(
|
||||
export const getHotelIdsFailCounter = meter.createCounter(
|
||||
"trpc.hotel.hotel-ids.get-fail"
|
||||
)
|
||||
|
||||
export const meetingRoomsCounter = meter.createCounter(
|
||||
"trpc.hotels.meetingRooms"
|
||||
)
|
||||
export const meetingRoomsSuccessCounter = meter.createCounter(
|
||||
"trpc.hotels.meetingRooms-success"
|
||||
)
|
||||
export const meetingRoomsFailCounter = meter.createCounter(
|
||||
"trpc.hotels.meetingRooms-fail"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user