feat: performance improvements
This commit is contained in:
@@ -69,7 +69,6 @@ export default async function StepPage({
|
|||||||
const hotelData = await getHotelData({
|
const hotelData = await getHotelData({
|
||||||
hotelId,
|
hotelId,
|
||||||
language: lang,
|
language: lang,
|
||||||
include: [HotelIncludeEnum.RoomCategories],
|
|
||||||
})
|
})
|
||||||
const roomAvailability = await getSelectedRoomAvailability({
|
const roomAvailability = await getSelectedRoomAvailability({
|
||||||
hotelId,
|
hotelId,
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ export default async function SelectRatePage({
|
|||||||
serverClient().hotel.hotelData.get({
|
serverClient().hotel.hotelData.get({
|
||||||
hotelId: searchParams.hotel,
|
hotelId: searchParams.hotel,
|
||||||
language: params.lang,
|
language: params.lang,
|
||||||
include: [HotelIncludeEnum.RoomCategories],
|
|
||||||
}),
|
}),
|
||||||
serverClient().hotel.availability.rooms({
|
serverClient().hotel.availability.rooms({
|
||||||
hotelId: parseInt(searchParams.hotel, 10),
|
hotelId: parseInt(searchParams.hotel, 10),
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ export default async function HotelPage() {
|
|||||||
const lang = getLang()
|
const lang = getLang()
|
||||||
const googleMapsApiKey = env.GOOGLE_STATIC_MAP_KEY
|
const googleMapsApiKey = env.GOOGLE_STATIC_MAP_KEY
|
||||||
const googleMapId = env.GOOGLE_DYNAMIC_MAP_ID
|
const googleMapId = env.GOOGLE_DYNAMIC_MAP_ID
|
||||||
const hotelData = await serverClient().hotel.get({
|
const hotelData = await serverClient().hotel.get()
|
||||||
include: ["RoomCategories"],
|
|
||||||
})
|
|
||||||
if (!hotelData) {
|
if (!hotelData) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { serverClient } from "@/lib/trpc/server"
|
import { getCurrentFooter } from "@/lib/trpc/memoizedRequests"
|
||||||
|
|
||||||
import Image from "@/components/Image"
|
import Image from "@/components/Image"
|
||||||
import { getLang } from "@/i18n/serverContext"
|
import { getLang } from "@/i18n/serverContext"
|
||||||
@@ -8,9 +8,7 @@ import Navigation from "./Navigation"
|
|||||||
import styles from "./footer.module.css"
|
import styles from "./footer.module.css"
|
||||||
|
|
||||||
export default async function Footer() {
|
export default async function Footer() {
|
||||||
const footerData = await serverClient().contentstack.base.currentFooter({
|
const footerData = await getCurrentFooter(getLang())
|
||||||
lang: getLang(),
|
|
||||||
})
|
|
||||||
if (!footerData) {
|
if (!footerData) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,18 +61,15 @@ export const getHotelData = cache(async function getMemoizedHotelData({
|
|||||||
hotelId,
|
hotelId,
|
||||||
language,
|
language,
|
||||||
isCardOnlyPayment,
|
isCardOnlyPayment,
|
||||||
include,
|
|
||||||
}: {
|
}: {
|
||||||
hotelId: string
|
hotelId: string
|
||||||
language: string
|
language: string
|
||||||
isCardOnlyPayment?: boolean
|
isCardOnlyPayment?: boolean
|
||||||
include?: HotelIncludeEnum[]
|
|
||||||
}) {
|
}) {
|
||||||
return serverClient().hotel.hotelData.get({
|
return serverClient().hotel.hotelData.get({
|
||||||
hotelId,
|
hotelId,
|
||||||
language,
|
language,
|
||||||
isCardOnlyPayment,
|
isCardOnlyPayment,
|
||||||
include,
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -120,6 +117,12 @@ export const getCurrentHeader = cache(async function getMemoizedCurrentHeader(
|
|||||||
return serverClient().contentstack.base.currentHeader({ lang })
|
return serverClient().contentstack.base.currentHeader({ lang })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const getCurrentFooter = cache(async function getMemoizedCurrentFooter(
|
||||||
|
lang: Lang
|
||||||
|
) {
|
||||||
|
return serverClient().contentstack.base.currentFooter({ lang })
|
||||||
|
})
|
||||||
|
|
||||||
export const getMyPagesNavigation = cache(
|
export const getMyPagesNavigation = cache(
|
||||||
async function getMemoizedMyPagesNavigation() {
|
async function getMemoizedMyPagesNavigation() {
|
||||||
return serverClient().contentstack.myPages.navigation.get()
|
return serverClient().contentstack.myPages.navigation.get()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { metrics } from "@opentelemetry/api"
|
import { metrics } from "@opentelemetry/api"
|
||||||
|
import { cache } from "react"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MembershipLevel,
|
MembershipLevel,
|
||||||
@@ -42,7 +43,7 @@ const getByLevelLoyaltyLevelFailCounter = meter.createCounter(
|
|||||||
"trpc.contentstack.loyaltyLevel.byLevel-fail"
|
"trpc.contentstack.loyaltyLevel.byLevel-fail"
|
||||||
)
|
)
|
||||||
|
|
||||||
export async function getAllLoyaltyLevels(ctx: Context) {
|
export const getAllLoyaltyLevels = cache(async (ctx: Context) => {
|
||||||
getAllLoyaltyLevelCounter.add(1)
|
getAllLoyaltyLevelCounter.add(1)
|
||||||
|
|
||||||
// Ideally we should fetch all available tiers from API, but since they
|
// Ideally we should fetch all available tiers from API, but since they
|
||||||
@@ -95,58 +96,60 @@ export async function getAllLoyaltyLevels(ctx: Context) {
|
|||||||
|
|
||||||
getAllLoyaltyLevelSuccessCounter.add(1)
|
getAllLoyaltyLevelSuccessCounter.add(1)
|
||||||
return validatedLoyaltyLevels.data
|
return validatedLoyaltyLevels.data
|
||||||
}
|
})
|
||||||
|
|
||||||
export async function getLoyaltyLevel(ctx: Context, level_id: MembershipLevel) {
|
export const getLoyaltyLevel = cache(
|
||||||
getByLevelLoyaltyLevelCounter.add(1, {
|
async (ctx: Context, level_id: MembershipLevel) => {
|
||||||
query: JSON.stringify({ lang: ctx.lang, level_id }),
|
getByLevelLoyaltyLevelCounter.add(1, {
|
||||||
})
|
query: JSON.stringify({ lang: ctx.lang, level_id }),
|
||||||
|
})
|
||||||
|
|
||||||
const loyaltyLevelsConfigResponse = await request<LoyaltyLevelsResponse>(
|
const loyaltyLevelsConfigResponse = await request<LoyaltyLevelsResponse>(
|
||||||
GetLoyaltyLevel,
|
GetLoyaltyLevel,
|
||||||
{ lang: ctx.lang, level_id },
|
{ lang: ctx.lang, level_id },
|
||||||
{
|
{
|
||||||
next: {
|
next: {
|
||||||
tags: [generateLoyaltyConfigTag(ctx.lang, "loyalty_level", level_id)],
|
tags: [generateLoyaltyConfigTag(ctx.lang, "loyalty_level", level_id)],
|
||||||
},
|
},
|
||||||
cache: "force-cache",
|
cache: "force-cache",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
!loyaltyLevelsConfigResponse.data ||
|
||||||
|
!loyaltyLevelsConfigResponse.data.all_loyalty_level.items.length
|
||||||
|
) {
|
||||||
|
getByLevelLoyaltyLevelFailCounter.add(1)
|
||||||
|
const notFoundError = notFound(loyaltyLevelsConfigResponse)
|
||||||
|
console.error(
|
||||||
|
"contentstack.loyaltyLevel not found error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang: ctx.lang, level_id },
|
||||||
|
error: { code: notFoundError.code },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw notFoundError
|
||||||
}
|
}
|
||||||
)
|
|
||||||
if (
|
|
||||||
!loyaltyLevelsConfigResponse.data ||
|
|
||||||
!loyaltyLevelsConfigResponse.data.all_loyalty_level.items.length
|
|
||||||
) {
|
|
||||||
getByLevelLoyaltyLevelFailCounter.add(1)
|
|
||||||
const notFoundError = notFound(loyaltyLevelsConfigResponse)
|
|
||||||
console.error(
|
|
||||||
"contentstack.loyaltyLevel not found error",
|
|
||||||
JSON.stringify({
|
|
||||||
query: { lang: ctx.lang, level_id },
|
|
||||||
error: { code: notFoundError.code },
|
|
||||||
})
|
|
||||||
)
|
|
||||||
throw notFoundError
|
|
||||||
}
|
|
||||||
|
|
||||||
const validatedLoyaltyLevels = validateLoyaltyLevelsSchema.safeParse(
|
const validatedLoyaltyLevels = validateLoyaltyLevelsSchema.safeParse(
|
||||||
loyaltyLevelsConfigResponse.data
|
loyaltyLevelsConfigResponse.data
|
||||||
)
|
|
||||||
if (!validatedLoyaltyLevels.success) {
|
|
||||||
getByLevelLoyaltyLevelFailCounter.add(1)
|
|
||||||
console.error(validatedLoyaltyLevels.error)
|
|
||||||
console.error(
|
|
||||||
"contentstack.loyaltyLevel validation error",
|
|
||||||
JSON.stringify({
|
|
||||||
query: { lang: ctx.lang, level_id },
|
|
||||||
error: validatedLoyaltyLevels.error,
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
return null
|
if (!validatedLoyaltyLevels.success) {
|
||||||
}
|
getByLevelLoyaltyLevelFailCounter.add(1)
|
||||||
|
console.error(validatedLoyaltyLevels.error)
|
||||||
|
console.error(
|
||||||
|
"contentstack.loyaltyLevel validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { lang: ctx.lang, level_id },
|
||||||
|
error: validatedLoyaltyLevels.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
getByLevelLoyaltyLevelSuccessCounter.add(1)
|
getByLevelLoyaltyLevelSuccessCounter.add(1)
|
||||||
return validatedLoyaltyLevels.data[0]
|
return validatedLoyaltyLevels.data[0]
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
export const loyaltyLevelQueryRouter = router({
|
export const loyaltyLevelQueryRouter = router({
|
||||||
byLevel: contentstackBaseProcedure
|
byLevel: contentstackBaseProcedure
|
||||||
|
|||||||
@@ -1,11 +1,5 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
export const getHotelInputSchema = z.object({
|
|
||||||
include: z
|
|
||||||
.array(z.enum(["RoomCategories", "NearbyHotels", "Restaurants", "City"]))
|
|
||||||
.optional(),
|
|
||||||
})
|
|
||||||
|
|
||||||
export const getHotelsAvailabilityInputSchema = z.object({
|
export const getHotelsAvailabilityInputSchema = z.object({
|
||||||
cityId: z.string(),
|
cityId: z.string(),
|
||||||
roomStayStartDate: z.string(),
|
roomStayStartDate: z.string(),
|
||||||
@@ -54,18 +48,17 @@ export const getRatesInputSchema = z.object({
|
|||||||
hotelId: z.string(),
|
hotelId: z.string(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export enum HotelIncludeEnum {
|
export const HotelIncludeEnum = z.enum([
|
||||||
"RoomCategories",
|
"RoomCategories",
|
||||||
"NearbyHotels",
|
"NearbyHotels",
|
||||||
"Restaurants",
|
"Restaurants",
|
||||||
"City",
|
"City",
|
||||||
}
|
])
|
||||||
|
|
||||||
export const getHotelDataInputSchema = z.object({
|
export const getHotelDataInputSchema = z.object({
|
||||||
hotelId: z.string(),
|
hotelId: z.string(),
|
||||||
language: z.string(),
|
language: z.string(),
|
||||||
isCardOnlyPayment: z.boolean().optional(),
|
isCardOnlyPayment: z.boolean().optional(),
|
||||||
include: z.array(z.nativeEnum(HotelIncludeEnum)).optional(),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export type HotelDataInput = z.input<typeof getHotelDataInputSchema>
|
export type HotelDataInput = z.input<typeof getHotelDataInputSchema>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { metrics } from "@opentelemetry/api"
|
import { metrics } from "@opentelemetry/api"
|
||||||
|
import { cache } from "react"
|
||||||
|
|
||||||
import { Lang } from "@/constants/languages"
|
import { Lang } from "@/constants/languages"
|
||||||
import * as api from "@/lib/api"
|
import * as api from "@/lib/api"
|
||||||
@@ -34,7 +35,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
getBreakfastPackageInputSchema,
|
getBreakfastPackageInputSchema,
|
||||||
getHotelDataInputSchema,
|
getHotelDataInputSchema,
|
||||||
getHotelInputSchema,
|
|
||||||
getHotelsAvailabilityInputSchema,
|
getHotelsAvailabilityInputSchema,
|
||||||
getRatesInputSchema,
|
getRatesInputSchema,
|
||||||
getRoomsAvailabilityInputSchema,
|
getRoomsAvailabilityInputSchema,
|
||||||
@@ -165,251 +165,249 @@ async function getContentstackData(lang: Lang, uid?: string | null) {
|
|||||||
return hotelPageData.data.hotel_page
|
return hotelPageData.data.hotel_page
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getHotelData(
|
export const getHotelData = cache(
|
||||||
input: HotelDataInput,
|
async (input: HotelDataInput, serviceToken: string) => {
|
||||||
serviceToken: string
|
const { hotelId, language, isCardOnlyPayment } = input
|
||||||
) {
|
|
||||||
const { hotelId, language, include, isCardOnlyPayment } = input
|
|
||||||
|
|
||||||
const params: Record<string, string> = {
|
const params: Record<string, string> = {
|
||||||
hotelId,
|
hotelId,
|
||||||
language,
|
language,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (include) {
|
params.include = HotelIncludeEnum.options.join(",")
|
||||||
params.include = include.join(",")
|
|
||||||
}
|
getHotelCounter.add(1, {
|
||||||
|
|
||||||
getHotelCounter.add(1, {
|
|
||||||
hotelId,
|
|
||||||
language,
|
|
||||||
include,
|
|
||||||
})
|
|
||||||
console.info(
|
|
||||||
"api.hotels.hotelData start",
|
|
||||||
JSON.stringify({ query: { hotelId, params } })
|
|
||||||
)
|
|
||||||
|
|
||||||
const apiResponse = await api.get(
|
|
||||||
api.endpoints.v1.Hotel.Hotels.hotel(hotelId),
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${serviceToken}`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
params
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
|
||||||
const text = await apiResponse.text()
|
|
||||||
getHotelFailCounter.add(1, {
|
|
||||||
hotelId,
|
hotelId,
|
||||||
language,
|
language,
|
||||||
include,
|
|
||||||
error_type: "http_error",
|
|
||||||
error: JSON.stringify({
|
|
||||||
status: apiResponse.status,
|
|
||||||
statusText: apiResponse.statusText,
|
|
||||||
text,
|
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
console.error(
|
console.info(
|
||||||
"api.hotels.hotelData error",
|
"api.hotels.hotelData start",
|
||||||
JSON.stringify({
|
JSON.stringify({ query: { hotelId, params } })
|
||||||
query: { hotelId, params },
|
)
|
||||||
error: {
|
|
||||||
|
const apiResponse = await api.get(
|
||||||
|
api.endpoints.v1.Hotel.Hotels.hotel(hotelId),
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${serviceToken}`,
|
||||||
|
},
|
||||||
|
// needs to clear default option as only
|
||||||
|
// cache or next.revalidate is permitted
|
||||||
|
cache: undefined,
|
||||||
|
next: {
|
||||||
|
revalidate: 60 * 30, // 30 minutes
|
||||||
|
},
|
||||||
|
},
|
||||||
|
params
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!apiResponse.ok) {
|
||||||
|
const text = await apiResponse.text()
|
||||||
|
getHotelFailCounter.add(1, {
|
||||||
|
hotelId,
|
||||||
|
language,
|
||||||
|
error_type: "http_error",
|
||||||
|
error: JSON.stringify({
|
||||||
status: apiResponse.status,
|
status: apiResponse.status,
|
||||||
statusText: apiResponse.statusText,
|
statusText: apiResponse.statusText,
|
||||||
text,
|
text,
|
||||||
},
|
}),
|
||||||
})
|
})
|
||||||
)
|
console.error(
|
||||||
return null
|
"api.hotels.hotelData error",
|
||||||
}
|
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
|
||||||
const validateHotelData = getHotelDataSchema.safeParse(apiJson)
|
|
||||||
|
|
||||||
if (!validateHotelData.success) {
|
|
||||||
getHotelFailCounter.add(1, {
|
|
||||||
hotelId,
|
|
||||||
language,
|
|
||||||
include,
|
|
||||||
error_type: "validation_error",
|
|
||||||
error: JSON.stringify(validateHotelData.error),
|
|
||||||
})
|
|
||||||
|
|
||||||
console.error(
|
|
||||||
"api.hotels.hotelData validation error",
|
|
||||||
JSON.stringify({
|
|
||||||
query: { hotelId, params },
|
|
||||||
error: validateHotelData.error,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
throw badRequestError()
|
|
||||||
}
|
|
||||||
|
|
||||||
getHotelSuccessCounter.add(1, {
|
|
||||||
hotelId,
|
|
||||||
language,
|
|
||||||
include,
|
|
||||||
})
|
|
||||||
console.info(
|
|
||||||
"api.hotels.hotelData success",
|
|
||||||
JSON.stringify({
|
|
||||||
query: { hotelId, params: params },
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
if (isCardOnlyPayment) {
|
|
||||||
validateHotelData.data.data.attributes.merchantInformationData.alternatePaymentOptions =
|
|
||||||
[]
|
|
||||||
}
|
|
||||||
|
|
||||||
return validateHotelData.data
|
|
||||||
}
|
|
||||||
|
|
||||||
export const hotelQueryRouter = router({
|
|
||||||
get: contentStackUidWithServiceProcedure
|
|
||||||
.input(getHotelInputSchema)
|
|
||||||
.query(async ({ ctx, input }) => {
|
|
||||||
const { lang, uid } = ctx
|
|
||||||
const { include } = input
|
|
||||||
|
|
||||||
const contentstackData = await getContentstackData(lang, uid)
|
|
||||||
const hotelId = contentstackData?.hotel_page_id
|
|
||||||
|
|
||||||
if (!hotelId) {
|
|
||||||
throw notFound(`Hotel not found for uid: ${uid}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const apiLang = toApiLang(lang)
|
|
||||||
const params: Record<string, string> = {
|
|
||||||
hotelId,
|
|
||||||
language: apiLang,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (include) {
|
|
||||||
params.include = include.join(",")
|
|
||||||
}
|
|
||||||
|
|
||||||
getHotelCounter.add(1, { hotelId, lang, include })
|
|
||||||
console.info(
|
|
||||||
"api.hotels.hotel start",
|
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
query: { hotelId, params },
|
query: { hotelId, params },
|
||||||
})
|
error: {
|
||||||
)
|
|
||||||
const apiResponse = await api.get(
|
|
||||||
api.endpoints.v1.Hotel.Hotels.hotel(hotelId),
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
params
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
|
||||||
const text = await apiResponse.text()
|
|
||||||
getHotelFailCounter.add(1, {
|
|
||||||
hotelId,
|
|
||||||
lang,
|
|
||||||
include,
|
|
||||||
error_type: "http_error",
|
|
||||||
error: JSON.stringify({
|
|
||||||
status: apiResponse.status,
|
status: apiResponse.status,
|
||||||
statusText: apiResponse.statusText,
|
statusText: apiResponse.statusText,
|
||||||
text,
|
text,
|
||||||
}),
|
},
|
||||||
})
|
|
||||||
console.error(
|
|
||||||
"api.hotels.hotel error",
|
|
||||||
JSON.stringify({
|
|
||||||
query: { hotelId, params },
|
|
||||||
error: {
|
|
||||||
status: apiResponse.status,
|
|
||||||
statusText: apiResponse.statusText,
|
|
||||||
text,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
)
|
|
||||||
throw serverErrorByStatus(apiResponse.status, apiResponse)
|
|
||||||
}
|
|
||||||
const apiJson = await apiResponse.json()
|
|
||||||
const validatedHotelData = getHotelDataSchema.safeParse(apiJson)
|
|
||||||
|
|
||||||
if (!validatedHotelData.success) {
|
|
||||||
getHotelFailCounter.add(1, {
|
|
||||||
hotelId,
|
|
||||||
lang,
|
|
||||||
include,
|
|
||||||
error_type: "validation_error",
|
|
||||||
error: JSON.stringify(validatedHotelData.error),
|
|
||||||
})
|
|
||||||
|
|
||||||
console.error(
|
|
||||||
"api.hotels.hotel validation error",
|
|
||||||
JSON.stringify({
|
|
||||||
query: { hotelId, params },
|
|
||||||
error: validatedHotelData.error,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
throw badRequestError()
|
|
||||||
}
|
|
||||||
|
|
||||||
const included = validatedHotelData.data.included || []
|
|
||||||
|
|
||||||
const hotelAttributes = validatedHotelData.data.data.attributes
|
|
||||||
const images = hotelAttributes.gallery?.smallerImages
|
|
||||||
const hotelAlerts = hotelAttributes.meta?.specialAlerts || []
|
|
||||||
|
|
||||||
const roomCategories = included
|
|
||||||
? included.filter((item) => item.type === "roomcategories")
|
|
||||||
: []
|
|
||||||
|
|
||||||
const activities = contentstackData?.content
|
|
||||||
? contentstackData?.content[0]
|
|
||||||
: null
|
|
||||||
|
|
||||||
const facilities: Facility[] = [
|
|
||||||
{
|
|
||||||
...apiJson.data.attributes.restaurantImages,
|
|
||||||
id: FacilityCardTypeEnum.restaurant,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...apiJson.data.attributes.conferencesAndMeetings,
|
|
||||||
id: FacilityCardTypeEnum.conference,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
...apiJson.data.attributes.healthAndWellness,
|
|
||||||
id: FacilityCardTypeEnum.wellness,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
getHotelSuccessCounter.add(1, { hotelId, lang, include })
|
|
||||||
console.info(
|
|
||||||
"api.hotels.hotel success",
|
|
||||||
JSON.stringify({
|
|
||||||
query: { hotelId, params: params },
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
return {
|
return null
|
||||||
hotelName: hotelAttributes.name,
|
}
|
||||||
hotelDescription: hotelAttributes.hotelContent.texts.descriptions.short,
|
|
||||||
hotelLocation: hotelAttributes.location,
|
const apiJson = await apiResponse.json()
|
||||||
hotelAddress: hotelAttributes.address,
|
const validateHotelData = getHotelDataSchema.safeParse(apiJson)
|
||||||
hotelRatings: hotelAttributes.ratings,
|
|
||||||
hotelDetailedFacilities: hotelAttributes.detailedFacilities,
|
if (!validateHotelData.success) {
|
||||||
hotelImages: images,
|
getHotelFailCounter.add(1, {
|
||||||
pointsOfInterest: hotelAttributes.pointsOfInterest,
|
hotelId,
|
||||||
roomCategories,
|
language,
|
||||||
activitiesCard: activities?.upcoming_activities_card,
|
error_type: "validation_error",
|
||||||
facilities,
|
error: JSON.stringify(validateHotelData.error),
|
||||||
alerts: hotelAlerts,
|
})
|
||||||
faq: contentstackData?.faq,
|
|
||||||
}
|
console.error(
|
||||||
}),
|
"api.hotels.hotelData validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params },
|
||||||
|
error: validateHotelData.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw badRequestError()
|
||||||
|
}
|
||||||
|
|
||||||
|
getHotelSuccessCounter.add(1, {
|
||||||
|
hotelId,
|
||||||
|
language,
|
||||||
|
})
|
||||||
|
console.info(
|
||||||
|
"api.hotels.hotelData success",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params: params },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isCardOnlyPayment) {
|
||||||
|
validateHotelData.data.data.attributes.merchantInformationData.alternatePaymentOptions =
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
|
||||||
|
return validateHotelData.data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export const hotelQueryRouter = router({
|
||||||
|
get: contentStackUidWithServiceProcedure.query(async ({ ctx }) => {
|
||||||
|
const { lang, uid } = ctx
|
||||||
|
|
||||||
|
const contentstackData = await getContentstackData(lang, uid)
|
||||||
|
const hotelId = contentstackData?.hotel_page_id
|
||||||
|
|
||||||
|
if (!hotelId) {
|
||||||
|
throw notFound(`Hotel not found for uid: ${uid}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const apiLang = toApiLang(lang)
|
||||||
|
const params: Record<string, string> = {
|
||||||
|
hotelId,
|
||||||
|
language: apiLang,
|
||||||
|
}
|
||||||
|
|
||||||
|
params.include = HotelIncludeEnum.options.join(",")
|
||||||
|
|
||||||
|
getHotelCounter.add(1, { hotelId, lang })
|
||||||
|
console.info(
|
||||||
|
"api.hotels.hotel start",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
const apiResponse = await api.get(
|
||||||
|
api.endpoints.v1.Hotel.Hotels.hotel(hotelId),
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||||
|
},
|
||||||
|
// needs to clear default option as only
|
||||||
|
// cache or next.revalidate is permitted
|
||||||
|
cache: undefined,
|
||||||
|
next: {
|
||||||
|
revalidate: 60 * 30, // 30 minutes
|
||||||
|
},
|
||||||
|
},
|
||||||
|
params
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!apiResponse.ok) {
|
||||||
|
const text = await apiResponse.text()
|
||||||
|
getHotelFailCounter.add(1, {
|
||||||
|
hotelId,
|
||||||
|
lang,
|
||||||
|
error_type: "http_error",
|
||||||
|
error: JSON.stringify({
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
console.error(
|
||||||
|
"api.hotels.hotel error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params },
|
||||||
|
error: {
|
||||||
|
status: apiResponse.status,
|
||||||
|
statusText: apiResponse.statusText,
|
||||||
|
text,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw serverErrorByStatus(apiResponse.status, apiResponse)
|
||||||
|
}
|
||||||
|
const apiJson = await apiResponse.json()
|
||||||
|
const validatedHotelData = getHotelDataSchema.safeParse(apiJson)
|
||||||
|
|
||||||
|
if (!validatedHotelData.success) {
|
||||||
|
getHotelFailCounter.add(1, {
|
||||||
|
hotelId,
|
||||||
|
lang,
|
||||||
|
error_type: "validation_error",
|
||||||
|
error: JSON.stringify(validatedHotelData.error),
|
||||||
|
})
|
||||||
|
|
||||||
|
console.error(
|
||||||
|
"api.hotels.hotel validation error",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params },
|
||||||
|
error: validatedHotelData.error,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
throw badRequestError()
|
||||||
|
}
|
||||||
|
|
||||||
|
const included = validatedHotelData.data.included || []
|
||||||
|
|
||||||
|
const hotelAttributes = validatedHotelData.data.data.attributes
|
||||||
|
const images = hotelAttributes.gallery?.smallerImages
|
||||||
|
const hotelAlerts = hotelAttributes.meta?.specialAlerts || []
|
||||||
|
|
||||||
|
const roomCategories = included
|
||||||
|
? included.filter((item) => item.type === "roomcategories")
|
||||||
|
: []
|
||||||
|
|
||||||
|
const activities = contentstackData?.content
|
||||||
|
? contentstackData?.content[0]
|
||||||
|
: null
|
||||||
|
|
||||||
|
const facilities: Facility[] = [
|
||||||
|
{
|
||||||
|
...apiJson.data.attributes.restaurantImages,
|
||||||
|
id: FacilityCardTypeEnum.restaurant,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...apiJson.data.attributes.conferencesAndMeetings,
|
||||||
|
id: FacilityCardTypeEnum.conference,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...apiJson.data.attributes.healthAndWellness,
|
||||||
|
id: FacilityCardTypeEnum.wellness,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
getHotelSuccessCounter.add(1, { hotelId, lang })
|
||||||
|
console.info(
|
||||||
|
"api.hotels.hotel success",
|
||||||
|
JSON.stringify({
|
||||||
|
query: { hotelId, params: params },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
hotelName: hotelAttributes.name,
|
||||||
|
hotelDescription: hotelAttributes.hotelContent.texts.descriptions.short,
|
||||||
|
hotelLocation: hotelAttributes.location,
|
||||||
|
hotelAddress: hotelAttributes.address,
|
||||||
|
hotelRatings: hotelAttributes.ratings,
|
||||||
|
hotelDetailedFacilities: hotelAttributes.detailedFacilities,
|
||||||
|
hotelImages: images,
|
||||||
|
pointsOfInterest: hotelAttributes.pointsOfInterest,
|
||||||
|
roomCategories,
|
||||||
|
activitiesCard: activities?.upcoming_activities_card,
|
||||||
|
facilities,
|
||||||
|
alerts: hotelAlerts,
|
||||||
|
faq: contentstackData?.faq,
|
||||||
|
}
|
||||||
|
}),
|
||||||
availability: router({
|
availability: router({
|
||||||
hotels: serviceProcedure
|
hotels: serviceProcedure
|
||||||
.input(getHotelsAvailabilityInputSchema)
|
.input(getHotelsAvailabilityInputSchema)
|
||||||
@@ -773,7 +771,6 @@ export const hotelQueryRouter = router({
|
|||||||
{
|
{
|
||||||
hotelId,
|
hotelId,
|
||||||
language: ctx.lang,
|
language: ctx.lang,
|
||||||
include: [HotelIncludeEnum.RoomCategories],
|
|
||||||
},
|
},
|
||||||
ctx.serviceToken
|
ctx.serviceToken
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user