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:
committed by
Linus Flood
parent
3f01266a75
commit
c3e3fa62ec
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user