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

@@ -78,6 +78,63 @@ export async function getBooking(
return booking.data
}
export async function findBooking(
confirmationNumber: string,
lang: Lang,
token: string,
lastName?: string,
firstName?: string,
email?: string
) {
const findBookingCounter = createCounter("booking", "find")
const metricsGetBooking = findBookingCounter.init({
confirmationNumber,
lastName,
firstName,
email,
})
metricsGetBooking.start()
const apiResponse = await api.post(
api.endpoints.v1.Booking.find(confirmationNumber),
{
headers: {
Authorization: `Bearer ${token}`,
},
body: {
lastName,
firstName,
email,
},
},
{ language: toApiLang(lang) }
)
if (!apiResponse.ok) {
await metricsGetBooking.httpError(apiResponse)
// If the booking is not found, return null.
// This scenario is expected to happen when a logged in user trying to access a booking that doesn't belong to them.
if (apiResponse.status === 400) {
return null
}
throw serverErrorByStatus(apiResponse.status, apiResponse)
}
const apiJson = await apiResponse.json()
const booking = bookingConfirmationSchema.safeParse(apiJson)
if (!booking.success) {
metricsGetBooking.validationError(booking.error)
throw badRequestError()
}
metricsGetBooking.success()
return booking.data
}
export async function cancelBooking(
confirmationNumber: string,
language: string,