fix: make sure calculations in booking flow are correct
This commit is contained in:
committed by
Michael Zetterberg
parent
3e0f503314
commit
a222ecfc5c
@@ -30,6 +30,7 @@ import { rateDefinitionSchema } from "./schemas/roomAvailability/rateDefinition"
|
||||
|
||||
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { RateEnum } from "@/types/enums/rate"
|
||||
import { RateTypeEnum } from "@/types/enums/rateType"
|
||||
import type {
|
||||
AdditionalData,
|
||||
@@ -112,11 +113,11 @@ export const hotelsAvailabilitySchema = z.object({
|
||||
function getRate(rate: RateDefinition) {
|
||||
switch (rate.cancellationRule) {
|
||||
case "CancellableBefore6PM":
|
||||
return "flex"
|
||||
return RateEnum.flex
|
||||
case "Changeable":
|
||||
return "change"
|
||||
return RateEnum.change
|
||||
case "NotCancellable":
|
||||
return "save"
|
||||
return RateEnum.save
|
||||
default:
|
||||
console.info(
|
||||
`Unknown cancellationRule [${rate.cancellationRule}]. This should never happen!`
|
||||
@@ -276,7 +277,6 @@ export const roomsAvailabilitySchema = z
|
||||
} else {
|
||||
product.bookingCode = undefined
|
||||
}
|
||||
product.breakfastIncluded = rateDefinition.breakfastIncluded
|
||||
product.rate = rate
|
||||
product.rateDefinition = rateDefinition
|
||||
|
||||
@@ -292,7 +292,9 @@ export const roomsAvailabilitySchema = z
|
||||
if ("corporateCheque" in product) {
|
||||
const rateDetails = getRateDetails(product)
|
||||
if (rateDetails) {
|
||||
breakfastIncluded.push(rateDetails.breakfastIncluded)
|
||||
breakfastIncluded.push(
|
||||
rateDetails.rateDefinition.breakfastIncluded
|
||||
)
|
||||
room.code.push({
|
||||
...rateDetails,
|
||||
corporateCheque: product.corporateCheque,
|
||||
@@ -304,7 +306,9 @@ export const roomsAvailabilitySchema = z
|
||||
if ("voucher" in product) {
|
||||
const rateDetails = getRateDetails(product)
|
||||
if (rateDetails) {
|
||||
breakfastIncluded.push(rateDetails.breakfastIncluded)
|
||||
breakfastIncluded.push(
|
||||
rateDetails.rateDefinition.breakfastIncluded
|
||||
)
|
||||
room.code.push({
|
||||
...rateDetails,
|
||||
voucher: product.voucher,
|
||||
@@ -319,7 +323,9 @@ export const roomsAvailabilitySchema = z
|
||||
for (const redemption of product) {
|
||||
const rateDetails = getRateDetails(redemption)
|
||||
if (rateDetails) {
|
||||
breakfastIncluded.push(rateDetails.breakfastIncluded)
|
||||
breakfastIncluded.push(
|
||||
rateDetails.rateDefinition.breakfastIncluded
|
||||
)
|
||||
room.redemptions.push({
|
||||
...redemption,
|
||||
...rateDetails,
|
||||
@@ -336,45 +342,46 @@ export const roomsAvailabilitySchema = z
|
||||
) {
|
||||
const memberRate = product.member
|
||||
const publicRate = product.public
|
||||
const rateCode = publicRate?.rateCode ?? memberRate?.rateCode
|
||||
const rateDetails = getRateDetails(product)
|
||||
const rateDetailsMember = getRateDetails({
|
||||
...product,
|
||||
public: null,
|
||||
})
|
||||
|
||||
if (rateDetails && rateCode) {
|
||||
if (rateDetails) {
|
||||
if (publicRate) {
|
||||
breakfastIncluded.push(
|
||||
rateDetails.rateDefinition.breakfastIncluded
|
||||
)
|
||||
}
|
||||
if (rateDetailsMember) {
|
||||
breakfastIncludedMember.push(
|
||||
rateDetailsMember.breakfastIncluded
|
||||
rateDetailsMember.rateDefinition.breakfastIncluded
|
||||
)
|
||||
rateDetails.rateDefinitionMember =
|
||||
rateDetailsMember.rateDefinition
|
||||
}
|
||||
const rateDefinition = findRateDefintion(rateCode)
|
||||
if (rateDefinition) {
|
||||
switch (rateDefinition.rateType) {
|
||||
case RateTypeEnum.PublicPromotion:
|
||||
room.campaign.push({
|
||||
...rateDetails,
|
||||
member: memberRate,
|
||||
public: publicRate,
|
||||
})
|
||||
break
|
||||
case RateTypeEnum.Regular:
|
||||
room.regular.push({
|
||||
...rateDetails,
|
||||
member: memberRate,
|
||||
public: publicRate,
|
||||
})
|
||||
break
|
||||
default:
|
||||
room.code.push({
|
||||
...rateDetails,
|
||||
member: memberRate,
|
||||
public: publicRate,
|
||||
})
|
||||
}
|
||||
switch (rateDetails.rateDefinition.rateType) {
|
||||
case RateTypeEnum.PublicPromotion:
|
||||
room.campaign.push({
|
||||
...rateDetails,
|
||||
member: memberRate,
|
||||
public: publicRate,
|
||||
})
|
||||
break
|
||||
case RateTypeEnum.Regular:
|
||||
room.regular.push({
|
||||
...rateDetails,
|
||||
member: memberRate,
|
||||
public: publicRate,
|
||||
})
|
||||
break
|
||||
default:
|
||||
room.code.push({
|
||||
...rateDetails,
|
||||
member: memberRate,
|
||||
public: publicRate,
|
||||
})
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -56,7 +56,10 @@ export const breakfastPackageSchema = z.object({
|
||||
description: z.string(),
|
||||
localPrice: packagePriceSchema,
|
||||
requestedPrice: packagePriceSchema,
|
||||
packageType: z.literal(PackageTypeEnum.BreakfastAdult),
|
||||
packageType: z.enum([
|
||||
PackageTypeEnum.BreakfastAdult,
|
||||
PackageTypeEnum.BreakfastChildren,
|
||||
]),
|
||||
})
|
||||
|
||||
export const ancillaryPackageSchema = z.object({
|
||||
|
||||
@@ -8,16 +8,16 @@ import {
|
||||
} from "../productTypePrice"
|
||||
import { rateDefinitionSchema } from "./rateDefinition"
|
||||
|
||||
import { RateEnum } from "@/types/enums/rate"
|
||||
|
||||
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.
|
||||
rate: z.enum(["change", "flex", "save"]).default("save"),
|
||||
rate: z.nativeEnum(RateEnum).default(RateEnum.save),
|
||||
rateDefinition: rateDefinitionSchema.optional().transform((val) =>
|
||||
val
|
||||
? val
|
||||
@@ -42,7 +42,6 @@ const baseProductSchema = z.object({
|
||||
function mapBaseProduct(baseProduct: typeof baseProductSchema._type) {
|
||||
return {
|
||||
bookingCode: baseProduct.bookingCode,
|
||||
breakfastIncluded: baseProduct.breakfastIncluded,
|
||||
rate: baseProduct.rate,
|
||||
rateDefinition: baseProduct.rateDefinition,
|
||||
rateDefinitionMember: baseProduct.rateDefinitionMember,
|
||||
@@ -97,14 +96,12 @@ export const redemptionsProduct = z
|
||||
data.map(
|
||||
({
|
||||
bookingCode,
|
||||
breakfastIncluded,
|
||||
rate,
|
||||
rateDefinition,
|
||||
rateDefinitionMember,
|
||||
...redemption
|
||||
}) => ({
|
||||
bookingCode,
|
||||
breakfastIncluded,
|
||||
rate,
|
||||
rateDefinition,
|
||||
rateDefinitionMember,
|
||||
|
||||
Reference in New Issue
Block a user