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
42 lines
1009 B
TypeScript
42 lines
1009 B
TypeScript
import { createCounter } from "@scandic-hotels/common/telemetry"
|
|
|
|
import * as api from "../../../api"
|
|
import { slimBookingSchema } from "../schema"
|
|
|
|
export async function priceChange(
|
|
{ confirmationNumber }: { confirmationNumber: string },
|
|
token: string
|
|
) {
|
|
const priceChangeCounter = createCounter("trpc.booking.price-change")
|
|
const metricsPriceChange = priceChangeCounter.init({ confirmationNumber })
|
|
|
|
metricsPriceChange.start()
|
|
|
|
const headers = {
|
|
Authorization: `Bearer ${token}`,
|
|
}
|
|
|
|
const apiResponse = await api.put(
|
|
api.endpoints.v1.Booking.priceChange(confirmationNumber),
|
|
{
|
|
headers,
|
|
}
|
|
)
|
|
|
|
if (!apiResponse.ok) {
|
|
await metricsPriceChange.httpError(apiResponse)
|
|
return null
|
|
}
|
|
|
|
const apiJson = await apiResponse.json()
|
|
const verifiedData = slimBookingSchema.safeParse(apiJson)
|
|
if (!verifiedData.success) {
|
|
metricsPriceChange.validationError(verifiedData.error)
|
|
return null
|
|
}
|
|
|
|
metricsPriceChange.success()
|
|
|
|
return verifiedData.data
|
|
}
|