Merged in feat/SW-1540-Fetch-correct-data-from-the-API (pull request #1309)
feat(SW-1551): Update schema for booking * feat(SW-1551): Update schema for booking * feat(SW-1551): Non breaking changes Approved-by: Michael Zetterberg
This commit is contained in:
@@ -63,9 +63,10 @@ export const createBookingSchema = z
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
// QUERY
|
// QUERY
|
||||||
const extraBedTypesSchema = z.object({
|
const childBedPreferencesSchema = z.object({
|
||||||
bedType: z.nativeEnum(ChildBedTypeEnum),
|
bedType: z.nativeEnum(ChildBedTypeEnum),
|
||||||
quantity: z.number().int(),
|
quantity: z.number().int(),
|
||||||
|
code: z.string().nullable().default(""),
|
||||||
})
|
})
|
||||||
|
|
||||||
const guestSchema = z.object({
|
const guestSchema = z.object({
|
||||||
@@ -76,13 +77,33 @@ const guestSchema = z.object({
|
|||||||
phoneNumber: phoneValidator().nullable().default(""),
|
phoneNumber: phoneValidator().nullable().default(""),
|
||||||
})
|
})
|
||||||
|
|
||||||
const packageSchema = z.object({
|
const packageSchema = z
|
||||||
code: z.string().nullable().default(""),
|
.object({
|
||||||
currency: z.string(),
|
description: z.string().nullable().default(""),
|
||||||
quantity: z.number().int(),
|
code: z.string().nullable().default(""),
|
||||||
totalPrice: z.number(),
|
price: z.object({
|
||||||
totalQuantity: z.number().int(),
|
unit: z.number().int().nullable(),
|
||||||
unitPrice: z.number(),
|
unitPrice: z.number(),
|
||||||
|
totalPrice: z.number().nullable(),
|
||||||
|
totalUnit: z.number().int().nullable(),
|
||||||
|
currency: z.string().default(""),
|
||||||
|
points: z.number().int().nullable(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.transform((packageData) => ({
|
||||||
|
description: packageData.description,
|
||||||
|
code: packageData.code,
|
||||||
|
currency: packageData.price.currency,
|
||||||
|
points: packageData.price.points,
|
||||||
|
totalPrice: packageData.price.totalPrice ?? 0,
|
||||||
|
totalUnit: packageData.price.totalUnit ?? 0,
|
||||||
|
unit: packageData.price.unit ?? 0,
|
||||||
|
unitPrice: packageData.price.unitPrice,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const ancillarySchema = z.object({
|
||||||
|
comment: z.string().default(""),
|
||||||
|
deliveryTime: z.string().default(""),
|
||||||
})
|
})
|
||||||
|
|
||||||
const rateDefinitionSchema = z.object({
|
const rateDefinitionSchema = z.object({
|
||||||
@@ -96,20 +117,37 @@ const rateDefinitionSchema = z.object({
|
|||||||
title: z.string().nullable().default(""),
|
title: z.string().nullable().default(""),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const linkedReservationsSchema = z.object({
|
||||||
|
confirmationNumber: z.string().default(""),
|
||||||
|
hotelId: z.string().default(""),
|
||||||
|
checkInDate: z.string().datetime(),
|
||||||
|
checkOutDate: z.string().datetime(),
|
||||||
|
cancellationNumber: z.string().default(""),
|
||||||
|
roomTypeCode: z.string().default(""),
|
||||||
|
adults: z.number().int(),
|
||||||
|
children: z.number().int(),
|
||||||
|
guaranteeCode: z.array(z.string()).default([]),
|
||||||
|
profileId: z.string().default(""),
|
||||||
|
})
|
||||||
|
|
||||||
export const bookingConfirmationSchema = z
|
export const bookingConfirmationSchema = z
|
||||||
.object({
|
.object({
|
||||||
data: z.object({
|
data: z.object({
|
||||||
attributes: z.object({
|
attributes: z.object({
|
||||||
adults: z.number().int(),
|
adults: z.number().int(),
|
||||||
|
ancillary: ancillarySchema,
|
||||||
checkInDate: z.date({ coerce: true }),
|
checkInDate: z.date({ coerce: true }),
|
||||||
checkOutDate: z.date({ coerce: true }),
|
checkOutDate: z.date({ coerce: true }),
|
||||||
createDateTime: z.date({ coerce: true }),
|
childBedPreferences: z.array(childBedPreferencesSchema).default([]),
|
||||||
childrenAges: z.array(z.number().int()).default([]),
|
childrenAges: z.array(z.number().int()).default([]),
|
||||||
extraBedTypes: z.array(extraBedTypesSchema).default([]),
|
canChangeDate: z.boolean(),
|
||||||
computedReservationStatus: z.string().nullable().default(""),
|
computedReservationStatus: z.string().nullable().default(""),
|
||||||
confirmationNumber: z.string().nullable().default(""),
|
confirmationNumber: z.string().nullable().default(""),
|
||||||
|
createDateTime: z.date({ coerce: true }),
|
||||||
currencyCode: z.string(),
|
currencyCode: z.string(),
|
||||||
guest: guestSchema,
|
guest: guestSchema,
|
||||||
|
isGuaranteedForLateArrival: z.boolean(),
|
||||||
|
linkedReservations: z.array(linkedReservationsSchema).default([]),
|
||||||
hotelId: z.string(),
|
hotelId: z.string(),
|
||||||
packages: z.array(packageSchema).default([]),
|
packages: z.array(packageSchema).default([]),
|
||||||
rateDefinition: rateDefinitionSchema,
|
rateDefinition: rateDefinitionSchema,
|
||||||
@@ -125,4 +163,7 @@ export const bookingConfirmationSchema = z
|
|||||||
type: z.literal("booking"),
|
type: z.literal("booking"),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.transform(({ data }) => data.attributes)
|
.transform(({ data }) => ({
|
||||||
|
...data.attributes,
|
||||||
|
extraBedTypes: data.attributes.childBedPreferences,
|
||||||
|
}))
|
||||||
|
|||||||
Reference in New Issue
Block a user