feat(BOOK-750): refactor booking endpoints * WIP * wip * wip * parse dates in UTC * wip * no more errors * Merge branch 'master' of bitbucket.org:scandic-swap/web into chore/refactor-trpc-booking-routes * . * cleanup * import named z from zod * fix(BOOK-750): updateBooking api endpoint expects dateOnly, we passed ISO date Approved-by: Anton Gunnarsson
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import { createCounter } from "@scandic-hotels/common/telemetry"
|
|
|
|
import { getBooking } from "../getBooking"
|
|
|
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
|
|
|
export async function getLinkedReservations(
|
|
{
|
|
confirmationNumber,
|
|
lang,
|
|
}: {
|
|
confirmationNumber: string
|
|
lang: Lang
|
|
},
|
|
token: string
|
|
): Promise<NonNullable<Awaited<ReturnType<typeof getBooking>>>[]> {
|
|
const getLinkedReservationsCounter = createCounter(
|
|
"booking.linkedReservations"
|
|
)
|
|
|
|
const metricsGetLinkedReservations = getLinkedReservationsCounter.init({
|
|
confirmationNumber,
|
|
})
|
|
|
|
metricsGetLinkedReservations.start()
|
|
|
|
const booking = await getBooking({ confirmationNumber, lang }, token)
|
|
|
|
if (!booking) {
|
|
return []
|
|
}
|
|
|
|
const linkedReservationsResults = await Promise.allSettled(
|
|
booking.linkedReservations.map((linkedReservation) =>
|
|
getBooking(
|
|
{ confirmationNumber: linkedReservation.confirmationNumber, lang },
|
|
token
|
|
)
|
|
)
|
|
)
|
|
|
|
const linkedReservations: NonNullable<
|
|
Awaited<ReturnType<typeof getBooking>>
|
|
>[] = []
|
|
for (const linkedReservationsResult of linkedReservationsResults) {
|
|
if (linkedReservationsResult.status !== "fulfilled") {
|
|
metricsGetLinkedReservations.dataError(`Failed to get linked reservation`)
|
|
continue
|
|
}
|
|
|
|
if (!linkedReservationsResult.value) {
|
|
metricsGetLinkedReservations.dataError(
|
|
`Unexpected value for linked reservation`
|
|
)
|
|
continue
|
|
}
|
|
|
|
linkedReservations.push(linkedReservationsResult.value)
|
|
}
|
|
|
|
metricsGetLinkedReservations.success()
|
|
|
|
return linkedReservations
|
|
}
|