Files
web/packages/trpc/lib/routers/hotels/availability/selectRate/rooms/index.ts
Hrishikesh Vaipurkar 78ede453a2 Merged in feat/SW-3526-show-sas-eb-points-rate-in- (pull request #2933)
feat(SW-3526): Show EB points rate and label in booking flow

* feat(SW-3526): Show EB points rate and label in booking flow

* feat(SW-3526) Optimized points currency code

* feat(SW-3526) Removed extra multiplication for token expiry after rebase

* feat(SW-3526): Updated to exhaustive check and thow if type error

Approved-by: Anton Gunnarsson
2025-10-15 06:54:44 +00:00

60 lines
1.8 KiB
TypeScript

import "server-only"
import { SEARCH_TYPE_REDEMPTION } from "../../../../../constants/booking"
import { unauthorizedError } from "../../../../../errors"
import { safeProtectedServiceProcedure } from "../../../../../procedures"
import { getRedemptionTokenSafely } from "../../../../../utils/getRedemptionTokenSafely"
import { getUserPointsBalance } from "../../../../../utils/getUserPointsBalance"
import { getRoomsAvailability } from "../../../services/getRoomsAvailability"
import { mergeRoomTypes } from "../../../utils"
import { selectRateRoomsAvailabilityInputSchema } from "./schema"
export const rooms = safeProtectedServiceProcedure
.input(selectRateRoomsAvailabilityInputSchema)
.use(async ({ ctx, input, next }) => {
if (input.booking.searchType === SEARCH_TYPE_REDEMPTION) {
if (ctx.session?.token.access_token) {
const pointsValue = await getUserPointsBalance(ctx.session)
const token = getRedemptionTokenSafely(ctx.session, ctx.serviceToken)
if (pointsValue && token) {
return next({
ctx: {
token: token,
userPoints: pointsValue ?? 0,
},
input,
})
}
}
throw unauthorizedError()
}
return next({
ctx: {
token: ctx.serviceToken,
},
})
})
.query(async function ({ ctx, input }) {
input.booking.rooms = input.booking.rooms.map((room) => ({
...room,
bookingCode: room.bookingCode || input.booking.bookingCode,
}))
const availability = await getRoomsAvailability(
input,
ctx.token,
ctx.serviceToken,
ctx.userPoints
)
for (const room of availability) {
if (!room || "error" in room) {
continue
}
room.roomConfigurations = mergeRoomTypes(room.roomConfigurations)
}
return availability
})