Merged in fix/rateCodes (pull request #1315)
fix: taking care of missing rateDefinitions * fix: taking care of missing rateDefinitions Approved-by: Linus Flood
This commit is contained in:
committed by
Linus Flood
parent
8d6f4b82f3
commit
4a06162f79
@@ -109,6 +109,23 @@ function everyRateHasBreakfastIncluded(
|
||||
return rateDefinition.breakfastIncluded
|
||||
}
|
||||
|
||||
function getRate(rate: RateDefinition | undefined) {
|
||||
if (!rate) {
|
||||
return null
|
||||
}
|
||||
switch (rate.cancellationRule) {
|
||||
case "CancellableBefore6PM":
|
||||
return "flex"
|
||||
case "Changeable":
|
||||
return "change"
|
||||
case "NotCancellable":
|
||||
return "save"
|
||||
default:
|
||||
console.info(`Should never happen!`)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used for custom sorting further down
|
||||
* to guarantee correct order of rates
|
||||
@@ -164,6 +181,32 @@ export const roomsAvailabilitySchema = z
|
||||
"public"
|
||||
)
|
||||
)
|
||||
|
||||
room.products = room.products.map((product) => {
|
||||
const publicRateDefinition = o.data.attributes.rateDefinitions.find(
|
||||
(rate) =>
|
||||
product.productType.public.rateCode
|
||||
? rate.rateCode === product.productType.public.rateCode
|
||||
: rate.rateCode === product.productType.public.oldRateCode
|
||||
)
|
||||
const publicRate = getRate(publicRateDefinition)
|
||||
const memberRateDefinition = o.data.attributes.rateDefinitions.find(
|
||||
(rate) =>
|
||||
product.productType.member?.rateCode
|
||||
? rate.rateCode === product.productType.member?.rateCode
|
||||
: rate.rateCode === product.productType.member?.oldRateCode
|
||||
)
|
||||
const memberRate = getRate(memberRateDefinition)
|
||||
|
||||
if (publicRate) {
|
||||
product.productType.public.rate = publicRate
|
||||
}
|
||||
if (memberRate && product.productType.member) {
|
||||
product.productType.member.rate = memberRate
|
||||
}
|
||||
|
||||
return product
|
||||
})
|
||||
}
|
||||
|
||||
// CancellationRule is the same for public and member per product
|
||||
|
||||
@@ -13,4 +13,10 @@ 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(""),
|
||||
})
|
||||
|
||||
@@ -53,9 +53,11 @@ export const roomConfigurationSchema = z
|
||||
productType: {
|
||||
member: {
|
||||
rateCode: "",
|
||||
oldRateCode: product.productType.member?.rateCode,
|
||||
},
|
||||
public: {
|
||||
rateCode: "",
|
||||
oldRateCode: product.productType.public.rateCode,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user