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,60 @@
|
||||
import { createCounter } from "@scandic-hotels/common/telemetry"
|
||||
|
||||
import * as api from "../../../api"
|
||||
import { toApiLang } from "../../../utils"
|
||||
import { bookingConfirmationSchema } from "../getBooking/schema"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
|
||||
export async function addPackageToBooking(
|
||||
{
|
||||
lang,
|
||||
...input
|
||||
}: {
|
||||
confirmationNumber: string
|
||||
lang: Lang
|
||||
packages: {
|
||||
code: string
|
||||
quantity: number
|
||||
comment?: string | undefined
|
||||
}[]
|
||||
ancillaryComment: string
|
||||
ancillaryDeliveryTime?: string | null | undefined
|
||||
},
|
||||
token: string
|
||||
) {
|
||||
const addPackageCounter = createCounter("trpc.booking.package.add")
|
||||
const metricsAddPackage = addPackageCounter.init({
|
||||
confirmationNumber: input.confirmationNumber,
|
||||
language: lang,
|
||||
})
|
||||
|
||||
metricsAddPackage.start()
|
||||
|
||||
const apiResponse = await api.post(
|
||||
api.endpoints.v1.Booking.packages(input.confirmationNumber),
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: input,
|
||||
},
|
||||
{ language: toApiLang(lang) }
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
await metricsAddPackage.httpError(apiResponse)
|
||||
return null
|
||||
}
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
const verifiedData = bookingConfirmationSchema.safeParse(apiJson)
|
||||
if (!verifiedData.success) {
|
||||
metricsAddPackage.validationError(verifiedData.error)
|
||||
return null
|
||||
}
|
||||
|
||||
metricsAddPackage.success()
|
||||
|
||||
return verifiedData.data
|
||||
}
|
||||
Reference in New Issue
Block a user