Merged in chore/refactor-trpc-booking-routes (pull request #3510)
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
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user