fix: add bookingCode to product
This commit is contained in:
@@ -49,7 +49,6 @@ import type {
|
||||
PriceChangeData,
|
||||
} from "@/types/components/hotelReservation/enterDetails/payment"
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { RateTypeEnum } from "@/types/enums/rateType"
|
||||
|
||||
const maxRetries = 15
|
||||
const retryInterval = 2000
|
||||
@@ -287,39 +286,9 @@ export default function PaymentClient({
|
||||
hotelId,
|
||||
language: lang,
|
||||
payment,
|
||||
rooms: rooms.map(({ room }, idx) => {
|
||||
let bookingCode = undefined
|
||||
if (room.roomRate.rateDefinition) {
|
||||
switch (room.roomRate.rateDefinition.rateType) {
|
||||
case RateTypeEnum.Regular:
|
||||
// do nothing, regular is not bookable with bookingCode
|
||||
break
|
||||
case RateTypeEnum.PublicPromotion:
|
||||
// PublicPromotion WITH CODE
|
||||
// only way to figure it out since API use the same
|
||||
// label for both yet only one should have bookingCoke
|
||||
if (
|
||||
booking.bookingCode === room.roomRate.rateDefinition.rateCode
|
||||
) {
|
||||
bookingCode = booking.bookingCode
|
||||
}
|
||||
break
|
||||
case RateTypeEnum.Arb:
|
||||
case RateTypeEnum.Company:
|
||||
case RateTypeEnum.CorporateCheque:
|
||||
case RateTypeEnum.Promotion:
|
||||
case RateTypeEnum.Redemption:
|
||||
case RateTypeEnum.TravelAgent:
|
||||
case RateTypeEnum.Voucher:
|
||||
default:
|
||||
bookingCode = booking.bookingCode
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
rooms: rooms.map(({ room }, idx) => ({
|
||||
adults: room.adults,
|
||||
bookingCode,
|
||||
bookingCode: room.roomRate.bookingCode,
|
||||
childrenAges: room.childrenInRoom?.map((child) => ({
|
||||
age: child.age,
|
||||
bedType: bedTypeMap[parseInt(child.bed.toString())],
|
||||
@@ -382,8 +351,7 @@ export default function PaymentClient({
|
||||
? room.specialRequest.comment
|
||||
: undefined,
|
||||
},
|
||||
}
|
||||
}),
|
||||
})),
|
||||
})
|
||||
},
|
||||
[
|
||||
|
||||
@@ -267,6 +267,11 @@ export const roomsAvailabilitySchema = z
|
||||
return null
|
||||
}
|
||||
|
||||
if (attributes.bookingCode) {
|
||||
product.bookingCode = attributes.bookingCode
|
||||
} else {
|
||||
product.bookingCode = undefined
|
||||
}
|
||||
product.breakfastIncluded = rateDefinition.breakfastIncluded
|
||||
product.rate = rate
|
||||
product.rateDefinition = rateDefinition
|
||||
|
||||
@@ -8,15 +8,10 @@ import {
|
||||
voucherProduct,
|
||||
} from "./product"
|
||||
|
||||
import {
|
||||
AvailabilityEnum,
|
||||
} from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||
import {
|
||||
RoomPackageCodeEnum,
|
||||
} from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
|
||||
export const roomConfigurationSchema = z
|
||||
.object({
|
||||
export const roomConfigurationSchema = z.object({
|
||||
breakfastIncludedInAllRatesMember: z.boolean().default(false),
|
||||
breakfastIncludedInAllRates: z.boolean().default(false),
|
||||
features: z
|
||||
@@ -43,28 +38,21 @@ export const roomConfigurationSchema = z
|
||||
// Red
|
||||
campaign: z
|
||||
.array(priceProduct)
|
||||
.nullish()
|
||||
.transform(val => val ? val.filter(Boolean) : []),
|
||||
.optional()
|
||||
.transform((val) => (val ? val.filter(Boolean) : [])),
|
||||
// Blue
|
||||
code: z
|
||||
.array(
|
||||
z
|
||||
.union([
|
||||
corporateChequeProduct,
|
||||
priceProduct,
|
||||
voucherProduct,
|
||||
])
|
||||
)
|
||||
.nullish()
|
||||
.transform(val => val ? val.filter(Boolean) : []),
|
||||
.array(z.union([corporateChequeProduct, priceProduct, voucherProduct]))
|
||||
.optional()
|
||||
.transform((val) => (val ? val.filter(Boolean) : [])),
|
||||
// Beige
|
||||
regular: z
|
||||
.array(priceProduct)
|
||||
.nullish()
|
||||
.transform(val => val ? val.filter(Boolean) : []),
|
||||
.optional()
|
||||
.transform((val) => (val ? val.filter(Boolean) : [])),
|
||||
// Burgundy
|
||||
redemptions: z
|
||||
.array(redemptionProduct)
|
||||
.nullish()
|
||||
.transform(val => val ? val.filter(Boolean) : []),
|
||||
.optional()
|
||||
.transform((val) => (val ? val.filter(Boolean) : [])),
|
||||
})
|
||||
|
||||
@@ -9,6 +9,11 @@ import {
|
||||
import { rateDefinitionSchema } from "./rateDefinition"
|
||||
|
||||
const baseProductSchema = z.object({
|
||||
// transform empty string to undefined
|
||||
bookingCode: z
|
||||
.string()
|
||||
.optional()
|
||||
.transform((val) => val),
|
||||
// Is breakfast included on product
|
||||
breakfastIncluded: z.boolean().default(false),
|
||||
// Used to set the rate that we use to chose titles etc.
|
||||
@@ -35,13 +40,14 @@ const baseProductSchema = z.object({
|
||||
|
||||
function mapBaseProduct(baseProduct: typeof baseProductSchema._type) {
|
||||
return {
|
||||
bookingCode: baseProduct.bookingCode,
|
||||
breakfastIncluded: baseProduct.breakfastIncluded,
|
||||
rate: baseProduct.rate,
|
||||
rateDefinition: baseProduct.rateDefinition,
|
||||
}
|
||||
}
|
||||
|
||||
const rawCorporateChequeProduct = z
|
||||
export const corporateChequeProduct = z
|
||||
.object({
|
||||
productType: z
|
||||
.object({
|
||||
@@ -52,21 +58,12 @@ const rawCorporateChequeProduct = z
|
||||
})),
|
||||
})
|
||||
.merge(baseProductSchema)
|
||||
|
||||
function transformCorporateCheque(
|
||||
data: z.output<typeof rawCorporateChequeProduct>
|
||||
) {
|
||||
return {
|
||||
.transform((data) => ({
|
||||
...data.productType,
|
||||
...mapBaseProduct(data),
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
||||
export const corporateChequeProduct = rawCorporateChequeProduct.transform(
|
||||
transformCorporateCheque
|
||||
)
|
||||
|
||||
const rawPriceProduct = z
|
||||
export const priceProduct = z
|
||||
.object({
|
||||
productType: z.object({
|
||||
member: productTypePriceSchema.nullish().default(null),
|
||||
@@ -74,30 +71,36 @@ const rawPriceProduct = z
|
||||
}),
|
||||
})
|
||||
.merge(baseProductSchema)
|
||||
|
||||
function transformPriceProduct(data: z.output<typeof rawPriceProduct>) {
|
||||
return {
|
||||
.transform((data) => ({
|
||||
...data.productType,
|
||||
...mapBaseProduct(data),
|
||||
}
|
||||
}
|
||||
|
||||
export const priceProduct = rawPriceProduct.transform(transformPriceProduct)
|
||||
}))
|
||||
|
||||
export const redemptionProduct = z
|
||||
.object({
|
||||
redemption: productTypePointsSchema,
|
||||
})
|
||||
.merge(baseProductSchema)
|
||||
.transform((data) => ({
|
||||
redemption: data.redemption,
|
||||
...mapBaseProduct(data),
|
||||
}))
|
||||
|
||||
const rawRedemptionsProduct = z.object({
|
||||
type: z.literal("REDEMPTION").optional().default("REDEMPTION"),
|
||||
export const redemptionsProduct = z
|
||||
.object({
|
||||
productType: z.object({
|
||||
redemptions: z
|
||||
.array(productTypePointsSchema.merge(baseProductSchema))
|
||||
.transform((data) =>
|
||||
data.map(
|
||||
({ breakfastIncluded, rate, rateDefinition, ...redemption }) => ({
|
||||
({
|
||||
bookingCode,
|
||||
breakfastIncluded,
|
||||
rate,
|
||||
rateDefinition,
|
||||
...redemption
|
||||
}) => ({
|
||||
bookingCode,
|
||||
breakfastIncluded,
|
||||
rate,
|
||||
rateDefinition,
|
||||
@@ -107,30 +110,19 @@ const rawRedemptionsProduct = z.object({
|
||||
),
|
||||
}),
|
||||
})
|
||||
.transform((data) => data.productType.redemptions)
|
||||
|
||||
export const redemptionsProduct = rawRedemptionsProduct.transform(
|
||||
(data) => data.productType.redemptions
|
||||
)
|
||||
|
||||
const rawVoucherProduct = z
|
||||
export const voucherProduct = z
|
||||
.object({
|
||||
type: z.literal("VOUCHER").optional().default("VOUCHER"),
|
||||
productType: z.object({
|
||||
voucher: productTypeVoucherSchema,
|
||||
}),
|
||||
})
|
||||
.merge(baseProductSchema)
|
||||
|
||||
function transformVoucherProduct(data: z.output<typeof rawVoucherProduct>) {
|
||||
return {
|
||||
.transform((data) => ({
|
||||
...data.productType,
|
||||
...mapBaseProduct(data),
|
||||
}
|
||||
}
|
||||
|
||||
export const voucherProduct = rawVoucherProduct.transform(
|
||||
transformVoucherProduct
|
||||
)
|
||||
}))
|
||||
|
||||
export const productSchema = z.union([
|
||||
corporateChequeProduct,
|
||||
@@ -138,24 +130,3 @@ export const productSchema = z.union([
|
||||
voucherProduct,
|
||||
priceProduct,
|
||||
])
|
||||
// export const productSchema = z.discriminatedUnion(
|
||||
// "type",
|
||||
// [
|
||||
// rawCorporateChequeProduct,
|
||||
// rawPriceProduct,
|
||||
// rawRedemptionsProduct,
|
||||
// rawVoucherProduct,
|
||||
// ]
|
||||
// )
|
||||
// .transform(data => {
|
||||
// switch (data.type) {
|
||||
// case "CORPORATECHEQUE":
|
||||
// return transformCorporateCheque(data)
|
||||
// case "PRICEPRODUCT":
|
||||
// return transformPriceProduct(data)
|
||||
// case "REDEMPTION":
|
||||
// return data.productType.redemptions
|
||||
// case "VOUCHER":
|
||||
// return transformVoucherProduct(data)
|
||||
// }
|
||||
// })
|
||||
|
||||
Reference in New Issue
Block a user