This commit is contained in:
Linus Flood
2025-05-02 12:17:18 +02:00
parent efcbde1647
commit 7c26e2955e
6 changed files with 195 additions and 3 deletions

View File

@@ -11,12 +11,13 @@ import { getHotel } from "../hotels/utils"
import { encrypt } from "../utils/encryption"
import {
createRefIdInput,
findBookingInput,
getBookingInput,
getBookingStatusInput,
getLinkedReservationsInput,
} from "./input"
import { createBookingSchema } from "./output"
import { getBookedHotelRoom, getBooking } from "./utils"
import { findBooking, getBookedHotelRoom, getBooking } from "./utils"
export const bookingQueryRouter = router({
get: safeProtectedServiceProcedure
@@ -69,6 +70,74 @@ export const bookingQueryRouter = router({
metricsGetBooking.success()
return {
...hotelData,
booking,
room: getBookedHotelRoom(
hotelData.roomCategories,
booking.roomTypeCode
),
}
}),
findBooking: safeProtectedServiceProcedure
.input(findBookingInput)
.use(async ({ ctx, input, next }) => {
const lang = input.lang ?? ctx.lang
const token = ctx.session?.token.access_token ?? ctx.serviceToken
return next({
ctx: {
lang,
token,
},
})
})
.query(async function ({
ctx,
input: { confirmationNumber, lastName, firstName, email },
}) {
const findBookingCounter = createCounter("trpc.booking", "findBooking")
const metricsFindBooking = findBookingCounter.init({ confirmationNumber })
metricsFindBooking.start()
const booking = await findBooking(
confirmationNumber,
ctx.lang,
ctx.token,
lastName,
firstName,
email
)
if (!booking) {
metricsFindBooking.dataError(
`Fail to find booking data for ${confirmationNumber}`,
{ confirmationNumber }
)
return null
}
const hotelData = await getHotel(
{
hotelId: booking.hotelId,
isCardOnlyPayment: false,
language: ctx.lang,
},
ctx.serviceToken
)
if (!hotelData) {
metricsFindBooking.dataError(
`Failed to find hotel data for ${booking.hotelId}`,
{
hotelId: booking.hotelId,
}
)
throw serverErrorByStatus(404)
}
metricsFindBooking.success()
return {
...hotelData,
booking,