fix: add bookingCode to product
This commit is contained in:
@@ -49,7 +49,6 @@ import type {
|
|||||||
PriceChangeData,
|
PriceChangeData,
|
||||||
} from "@/types/components/hotelReservation/enterDetails/payment"
|
} from "@/types/components/hotelReservation/enterDetails/payment"
|
||||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
import { RateTypeEnum } from "@/types/enums/rateType"
|
|
||||||
|
|
||||||
const maxRetries = 15
|
const maxRetries = 15
|
||||||
const retryInterval = 2000
|
const retryInterval = 2000
|
||||||
@@ -287,39 +286,9 @@ export default function PaymentClient({
|
|||||||
hotelId,
|
hotelId,
|
||||||
language: lang,
|
language: lang,
|
||||||
payment,
|
payment,
|
||||||
rooms: rooms.map(({ room }, idx) => {
|
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 {
|
|
||||||
adults: room.adults,
|
adults: room.adults,
|
||||||
bookingCode,
|
bookingCode: room.roomRate.bookingCode,
|
||||||
childrenAges: room.childrenInRoom?.map((child) => ({
|
childrenAges: room.childrenInRoom?.map((child) => ({
|
||||||
age: child.age,
|
age: child.age,
|
||||||
bedType: bedTypeMap[parseInt(child.bed.toString())],
|
bedType: bedTypeMap[parseInt(child.bed.toString())],
|
||||||
@@ -382,8 +351,7 @@ export default function PaymentClient({
|
|||||||
? room.specialRequest.comment
|
? room.specialRequest.comment
|
||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
}
|
})),
|
||||||
}),
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -267,6 +267,11 @@ export const roomsAvailabilitySchema = z
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (attributes.bookingCode) {
|
||||||
|
product.bookingCode = attributes.bookingCode
|
||||||
|
} else {
|
||||||
|
product.bookingCode = undefined
|
||||||
|
}
|
||||||
product.breakfastIncluded = rateDefinition.breakfastIncluded
|
product.breakfastIncluded = rateDefinition.breakfastIncluded
|
||||||
product.rate = rate
|
product.rate = rate
|
||||||
product.rateDefinition = rateDefinition
|
product.rateDefinition = rateDefinition
|
||||||
|
|||||||
@@ -8,15 +8,10 @@ import {
|
|||||||
voucherProduct,
|
voucherProduct,
|
||||||
} from "./product"
|
} from "./product"
|
||||||
|
|
||||||
import {
|
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||||
AvailabilityEnum,
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
} from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
|
||||||
import {
|
|
||||||
RoomPackageCodeEnum,
|
|
||||||
} from "@/types/components/hotelReservation/selectRate/roomFilter"
|
|
||||||
|
|
||||||
export const roomConfigurationSchema = z
|
export const roomConfigurationSchema = z.object({
|
||||||
.object({
|
|
||||||
breakfastIncludedInAllRatesMember: z.boolean().default(false),
|
breakfastIncludedInAllRatesMember: z.boolean().default(false),
|
||||||
breakfastIncludedInAllRates: z.boolean().default(false),
|
breakfastIncludedInAllRates: z.boolean().default(false),
|
||||||
features: z
|
features: z
|
||||||
@@ -43,28 +38,21 @@ export const roomConfigurationSchema = z
|
|||||||
// Red
|
// Red
|
||||||
campaign: z
|
campaign: z
|
||||||
.array(priceProduct)
|
.array(priceProduct)
|
||||||
.nullish()
|
.optional()
|
||||||
.transform(val => val ? val.filter(Boolean) : []),
|
.transform((val) => (val ? val.filter(Boolean) : [])),
|
||||||
// Blue
|
// Blue
|
||||||
code: z
|
code: z
|
||||||
.array(
|
.array(z.union([corporateChequeProduct, priceProduct, voucherProduct]))
|
||||||
z
|
.optional()
|
||||||
.union([
|
.transform((val) => (val ? val.filter(Boolean) : [])),
|
||||||
corporateChequeProduct,
|
|
||||||
priceProduct,
|
|
||||||
voucherProduct,
|
|
||||||
])
|
|
||||||
)
|
|
||||||
.nullish()
|
|
||||||
.transform(val => val ? val.filter(Boolean) : []),
|
|
||||||
// Beige
|
// Beige
|
||||||
regular: z
|
regular: z
|
||||||
.array(priceProduct)
|
.array(priceProduct)
|
||||||
.nullish()
|
.optional()
|
||||||
.transform(val => val ? val.filter(Boolean) : []),
|
.transform((val) => (val ? val.filter(Boolean) : [])),
|
||||||
// Burgundy
|
// Burgundy
|
||||||
redemptions: z
|
redemptions: z
|
||||||
.array(redemptionProduct)
|
.array(redemptionProduct)
|
||||||
.nullish()
|
.optional()
|
||||||
.transform(val => val ? val.filter(Boolean) : []),
|
.transform((val) => (val ? val.filter(Boolean) : [])),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ import {
|
|||||||
import { rateDefinitionSchema } from "./rateDefinition"
|
import { rateDefinitionSchema } from "./rateDefinition"
|
||||||
|
|
||||||
const baseProductSchema = z.object({
|
const baseProductSchema = z.object({
|
||||||
|
// transform empty string to undefined
|
||||||
|
bookingCode: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.transform((val) => val),
|
||||||
// Is breakfast included on product
|
// Is breakfast included on product
|
||||||
breakfastIncluded: z.boolean().default(false),
|
breakfastIncluded: z.boolean().default(false),
|
||||||
// Used to set the rate that we use to chose titles etc.
|
// 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) {
|
function mapBaseProduct(baseProduct: typeof baseProductSchema._type) {
|
||||||
return {
|
return {
|
||||||
|
bookingCode: baseProduct.bookingCode,
|
||||||
breakfastIncluded: baseProduct.breakfastIncluded,
|
breakfastIncluded: baseProduct.breakfastIncluded,
|
||||||
rate: baseProduct.rate,
|
rate: baseProduct.rate,
|
||||||
rateDefinition: baseProduct.rateDefinition,
|
rateDefinition: baseProduct.rateDefinition,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawCorporateChequeProduct = z
|
export const corporateChequeProduct = z
|
||||||
.object({
|
.object({
|
||||||
productType: z
|
productType: z
|
||||||
.object({
|
.object({
|
||||||
@@ -52,21 +58,12 @@ const rawCorporateChequeProduct = z
|
|||||||
})),
|
})),
|
||||||
})
|
})
|
||||||
.merge(baseProductSchema)
|
.merge(baseProductSchema)
|
||||||
|
.transform((data) => ({
|
||||||
function transformCorporateCheque(
|
|
||||||
data: z.output<typeof rawCorporateChequeProduct>
|
|
||||||
) {
|
|
||||||
return {
|
|
||||||
...data.productType,
|
...data.productType,
|
||||||
...mapBaseProduct(data),
|
...mapBaseProduct(data),
|
||||||
}
|
}))
|
||||||
}
|
|
||||||
|
|
||||||
export const corporateChequeProduct = rawCorporateChequeProduct.transform(
|
export const priceProduct = z
|
||||||
transformCorporateCheque
|
|
||||||
)
|
|
||||||
|
|
||||||
const rawPriceProduct = z
|
|
||||||
.object({
|
.object({
|
||||||
productType: z.object({
|
productType: z.object({
|
||||||
member: productTypePriceSchema.nullish().default(null),
|
member: productTypePriceSchema.nullish().default(null),
|
||||||
@@ -74,30 +71,36 @@ const rawPriceProduct = z
|
|||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.merge(baseProductSchema)
|
.merge(baseProductSchema)
|
||||||
|
.transform((data) => ({
|
||||||
function transformPriceProduct(data: z.output<typeof rawPriceProduct>) {
|
|
||||||
return {
|
|
||||||
...data.productType,
|
...data.productType,
|
||||||
...mapBaseProduct(data),
|
...mapBaseProduct(data),
|
||||||
}
|
}))
|
||||||
}
|
|
||||||
|
|
||||||
export const priceProduct = rawPriceProduct.transform(transformPriceProduct)
|
|
||||||
|
|
||||||
export const redemptionProduct = z
|
export const redemptionProduct = z
|
||||||
.object({
|
.object({
|
||||||
redemption: productTypePointsSchema,
|
redemption: productTypePointsSchema,
|
||||||
})
|
})
|
||||||
.merge(baseProductSchema)
|
.merge(baseProductSchema)
|
||||||
|
.transform((data) => ({
|
||||||
|
redemption: data.redemption,
|
||||||
|
...mapBaseProduct(data),
|
||||||
|
}))
|
||||||
|
|
||||||
const rawRedemptionsProduct = z.object({
|
export const redemptionsProduct = z
|
||||||
type: z.literal("REDEMPTION").optional().default("REDEMPTION"),
|
.object({
|
||||||
productType: z.object({
|
productType: z.object({
|
||||||
redemptions: z
|
redemptions: z
|
||||||
.array(productTypePointsSchema.merge(baseProductSchema))
|
.array(productTypePointsSchema.merge(baseProductSchema))
|
||||||
.transform((data) =>
|
.transform((data) =>
|
||||||
data.map(
|
data.map(
|
||||||
({ breakfastIncluded, rate, rateDefinition, ...redemption }) => ({
|
({
|
||||||
|
bookingCode,
|
||||||
|
breakfastIncluded,
|
||||||
|
rate,
|
||||||
|
rateDefinition,
|
||||||
|
...redemption
|
||||||
|
}) => ({
|
||||||
|
bookingCode,
|
||||||
breakfastIncluded,
|
breakfastIncluded,
|
||||||
rate,
|
rate,
|
||||||
rateDefinition,
|
rateDefinition,
|
||||||
@@ -106,31 +109,20 @@ const rawRedemptionsProduct = z.object({
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
.transform((data) => data.productType.redemptions)
|
||||||
|
|
||||||
export const redemptionsProduct = rawRedemptionsProduct.transform(
|
export const voucherProduct = z
|
||||||
(data) => data.productType.redemptions
|
|
||||||
)
|
|
||||||
|
|
||||||
const rawVoucherProduct = z
|
|
||||||
.object({
|
.object({
|
||||||
type: z.literal("VOUCHER").optional().default("VOUCHER"),
|
|
||||||
productType: z.object({
|
productType: z.object({
|
||||||
voucher: productTypeVoucherSchema,
|
voucher: productTypeVoucherSchema,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.merge(baseProductSchema)
|
.merge(baseProductSchema)
|
||||||
|
.transform((data) => ({
|
||||||
function transformVoucherProduct(data: z.output<typeof rawVoucherProduct>) {
|
|
||||||
return {
|
|
||||||
...data.productType,
|
...data.productType,
|
||||||
...mapBaseProduct(data),
|
...mapBaseProduct(data),
|
||||||
}
|
}))
|
||||||
}
|
|
||||||
|
|
||||||
export const voucherProduct = rawVoucherProduct.transform(
|
|
||||||
transformVoucherProduct
|
|
||||||
)
|
|
||||||
|
|
||||||
export const productSchema = z.union([
|
export const productSchema = z.union([
|
||||||
corporateChequeProduct,
|
corporateChequeProduct,
|
||||||
@@ -138,24 +130,3 @@ export const productSchema = z.union([
|
|||||||
voucherProduct,
|
voucherProduct,
|
||||||
priceProduct,
|
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