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
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { z } from "zod"
|
|
|
|
import { calculateRefId } from "../../../utils/refId"
|
|
import { bookingReservationStatusSchema } from "../schema/bookingReservationStatusSchema"
|
|
|
|
export type BookingStatus = z.infer<typeof bookingStatusSchema>
|
|
export const bookingStatusSchema = z
|
|
.object({
|
|
data: z.object({
|
|
attributes: z.object({
|
|
reservationStatus: bookingReservationStatusSchema,
|
|
paymentUrl: z.string().nullable().optional(),
|
|
paymentMethod: z.string().nullable().optional(),
|
|
rooms: z
|
|
.array(
|
|
z.object({
|
|
confirmationNumber: z.string(),
|
|
cancellationNumber: z.string().nullable(),
|
|
priceChangedMetadata: z
|
|
.object({
|
|
roomPrice: z.number(),
|
|
totalPrice: z.number(),
|
|
})
|
|
.nullable()
|
|
.optional(),
|
|
})
|
|
)
|
|
.default([]),
|
|
errors: z
|
|
.array(
|
|
z.object({
|
|
confirmationNumber: z.string().nullable().optional(),
|
|
errorCode: z.string(),
|
|
description: z.string().nullable().optional(),
|
|
meta: z
|
|
.record(z.string(), z.union([z.string(), z.number()]))
|
|
.nullable()
|
|
.optional(),
|
|
})
|
|
)
|
|
.default([]),
|
|
}),
|
|
type: z.string(),
|
|
id: z.string(),
|
|
}),
|
|
})
|
|
.transform((d) => ({
|
|
id: d.data.id,
|
|
type: d.data.type,
|
|
reservationStatus: d.data.attributes.reservationStatus,
|
|
paymentUrl: d.data.attributes.paymentUrl,
|
|
paymentMethod: d.data.attributes.paymentMethod,
|
|
errors: d.data.attributes.errors,
|
|
rooms: d.data.attributes.rooms.map((room) => {
|
|
const lastName = ""
|
|
return {
|
|
...room,
|
|
refId: calculateRefId(room.confirmationNumber, lastName),
|
|
}
|
|
}),
|
|
}))
|