Distributed cache * cache deleteKey now uses an options object instead of a lonely argument variable fuzzy * merge * remove debug logs and cleanup * cleanup * add fault handling * add fault handling * add pid when logging redis client creation * add identifier when logging redis client creation * cleanup * feat: add redis-api as it's own app * feature: use http wrapper for redis * feat: add the possibility to fallback to unstable_cache * Add error handling if redis cache is unresponsive * add logging for unstable_cache * merge * don't cache errors * fix: metadatabase on branchdeploys * Handle when /en/destinations throws add ErrorBoundary * Add sentry-logging when ErrorBoundary catches exception * Fix error handling for distributed cache * cleanup code * Added Application Insights back * Update generateApiKeys script and remove duplicate * Merge branch 'feature/redis' of bitbucket.org:scandic-swap/web into feature/redis * merge Approved-by: Linus Flood
90 lines
2.3 KiB
TypeScript
90 lines
2.3 KiB
TypeScript
import { trpc } from "@/lib/trpc/client"
|
|
|
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
|
import type { Child } from "@/types/components/hotelReservation/selectRate/selectRate"
|
|
import type { RoomsAvailability } from "@/types/trpc/routers/hotel/roomAvailability"
|
|
import type { Lang } from "@/constants/languages"
|
|
|
|
export function combineRoomAvailabilities(
|
|
availabilityResults: PromiseSettledResult<RoomsAvailability | null>[]
|
|
) {
|
|
return availabilityResults.reduce<RoomsAvailability | null>((acc, result) => {
|
|
if (result.status === "fulfilled" && result.value) {
|
|
if (acc) {
|
|
acc = {
|
|
...acc,
|
|
roomConfigurations: [
|
|
...acc.roomConfigurations,
|
|
...result.value.roomConfigurations,
|
|
],
|
|
}
|
|
} else {
|
|
acc = result.value
|
|
}
|
|
}
|
|
|
|
// Ping monitoring about fail?
|
|
if (result.status === "rejected") {
|
|
console.info(`RoomAvailability fetch failed`)
|
|
console.error(result.reason)
|
|
}
|
|
|
|
return acc
|
|
}, null)
|
|
}
|
|
|
|
export function useRoomsAvailability(
|
|
uniqueAdultsCount: number[],
|
|
hotelId: number,
|
|
fromDateString: string,
|
|
toDateString: string,
|
|
lang: Lang,
|
|
childArray?: Child[],
|
|
bookingCode?: string
|
|
) {
|
|
const returnValue =
|
|
trpc.hotel.availability.roomsCombinedAvailability.useQuery({
|
|
hotelId,
|
|
roomStayStartDate: fromDateString,
|
|
roomStayEndDate: toDateString,
|
|
uniqueAdultsCount,
|
|
childArray,
|
|
lang,
|
|
bookingCode,
|
|
})
|
|
|
|
const combinedAvailability = returnValue.data?.length
|
|
? combineRoomAvailabilities(
|
|
returnValue.data as PromiseSettledResult<RoomsAvailability | null>[]
|
|
)
|
|
: null
|
|
|
|
return {
|
|
...returnValue,
|
|
data: combinedAvailability,
|
|
}
|
|
}
|
|
|
|
export function useHotelPackages(
|
|
adultArray: number[],
|
|
childArray: Child[] | undefined,
|
|
fromDateString: string,
|
|
toDateString: string,
|
|
hotelId: number,
|
|
lang: Lang
|
|
) {
|
|
return trpc.hotel.packages.get.useQuery({
|
|
adults: adultArray[0], // Using the first adult count
|
|
children: childArray ? childArray.length : undefined,
|
|
endDate: toDateString,
|
|
hotelId: hotelId.toString(),
|
|
packageCodes: [
|
|
RoomPackageCodeEnum.ACCESSIBILITY_ROOM,
|
|
RoomPackageCodeEnum.PET_ROOM,
|
|
RoomPackageCodeEnum.ALLERGY_ROOM,
|
|
],
|
|
startDate: fromDateString,
|
|
lang: lang,
|
|
})
|
|
}
|