Merged in fix/allow-single-rateCode (pull request #1438)

fix: allow rates that only have either of member or public to be selectable

* fix: allow rates that only have either of member or public to be selectable


Approved-by: Michael Zetterberg
This commit is contained in:
Simon.Emanuelsson
2025-03-03 08:28:55 +00:00
committed by Linus Flood
parent 3f01266a75
commit c3e3fa62ec
30 changed files with 487 additions and 573 deletions

View File

@@ -15,10 +15,4 @@ export const productTypePriceSchema = z.object({
rateCode: z.string(),
rateType: z.string().optional(),
requestedPrice: priceSchema.optional(),
// This is only used when a product is filtered out
// so that we can still map out the correct titles a.so.
oldRateCode: z.string().default(""),
// Used to set the rate that we use to chose
// titles etc.
rate: z.string().default(""),
})

View File

@@ -1,11 +1,9 @@
import deepmerge from "deepmerge"
import { z } from "zod"
import { productSchema } from "./product"
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
import { RateTypeEnum } from "@/types/enums/rateType"
export const roomConfigurationSchema = z
.object({
@@ -31,60 +29,15 @@ export const roomConfigurationSchema = z
})
.transform((data) => {
if (data.products.length) {
const someProductsMissAtLeastOneRateCode = data.products.some(
({ productType }) =>
!productType.public.rateCode || !productType.member?.rateCode
)
if (someProductsMissAtLeastOneRateCode) {
data.products = data.products.map((product) => {
if (
product.productType.public.rateCode &&
product.productType.member?.rateCode
) {
return product
}
// Return rate with only public available when it is a booking code rate
// which can be any one of other rate types
if (product.productType.public.rateType !== RateTypeEnum.Regular) {
return product
}
/**
* Reset both rateCodes if one is missing to show `No prices available` for the same reason as
* mentioned above.
*
* TODO: (Maybe) notify somewhere that this happened
*/
return deepmerge(product, {
productType: {
member: {
rateCode: "",
oldRateCode: product.productType.member?.rateCode,
},
public: {
rateCode: "",
oldRateCode: product.productType.public.rateCode,
},
},
})
})
}
/**
* When all products miss at least one rateCode (member or public), we change the status to NotAvailable
* since we cannot as of now (31 january) guarantee the flow with missing rateCodes.
* This rule applies to regular rates (Save, Change and Flex)
* Exception Booking code rate
*
* TODO: (Maybe) notify somewhere that this happened
* Just guaranteeing that if all products all miss
* both public and member rateCode that status is
* set to `NotAvailable`
*/
const allProductsMissAtLeastOneRateCode = data.products.every(
({ productType }) =>
(!productType.public.rateCode || !productType.member?.rateCode) &&
productType.public.rateType === RateTypeEnum.Regular
const allProductsMissBothRateCodes = data.products.every(
(product) => !product.public?.rateCode && !product.member?.rateCode
)
if (allProductsMissAtLeastOneRateCode) {
if (allProductsMissBothRateCodes) {
data.status = AvailabilityEnum.NotAvailable
}
}

View File

@@ -2,20 +2,19 @@ import { z } from "zod"
import { productTypePriceSchema } from "../productTypePrice"
import { CurrencyEnum } from "@/types/enums/currency"
export const productSchema = z.object({
productType: z.object({
member: productTypePriceSchema.optional(),
public: productTypePriceSchema.default({
localPrice: {
currency: CurrencyEnum.SEK,
pricePerNight: 0,
pricePerStay: 0,
},
rateCode: "",
rateType: "",
requestedPrice: undefined,
export const productSchema = z
.object({
// Is product flex rate
isFlex: z.boolean().default(false),
productType: z.object({
member: productTypePriceSchema.optional(),
public: productTypePriceSchema.optional(),
}),
}),
})
// Used to set the rate that we use to chose titles etc.
rate: z.enum(["change", "flex", "save"]).default("save"),
})
.transform((data) => ({
...data.productType,
isFlex: data.isFlex,
rate: data.rate,
}))