feat: SW-2028 Implemented validation for not enough points details page
This commit is contained in:
@@ -657,12 +657,16 @@ export const hotelQueryRouter = router({
|
||||
.use(async ({ ctx, input, next }) => {
|
||||
if (input.redemption) {
|
||||
if (ctx.session?.token.access_token) {
|
||||
return next({
|
||||
ctx: {
|
||||
token: ctx.session.token.access_token,
|
||||
},
|
||||
input,
|
||||
})
|
||||
const verifiedUser = await getVerifiedUser({ session: ctx.session })
|
||||
if (!verifiedUser?.error) {
|
||||
return next({
|
||||
ctx: {
|
||||
token: ctx.session.token.access_token,
|
||||
userPoints: verifiedUser?.data.membership?.currentPoints,
|
||||
},
|
||||
input,
|
||||
})
|
||||
}
|
||||
}
|
||||
throw unauthorizedError()
|
||||
}
|
||||
@@ -677,7 +681,8 @@ export const hotelQueryRouter = router({
|
||||
let selectedRoomData = await getSelectedRoomAvailability(
|
||||
input,
|
||||
toApiLang(ctx.lang),
|
||||
ctx.token
|
||||
ctx.token,
|
||||
ctx.userPoints
|
||||
)
|
||||
|
||||
const {
|
||||
|
||||
@@ -575,7 +575,8 @@ function findProduct(product: Products, rateDefinition: RateDefinition) {
|
||||
export async function getSelectedRoomAvailability(
|
||||
input: z.input<typeof selectedRoomAvailabilityInputSchema>,
|
||||
lang: string,
|
||||
serviceToken: string
|
||||
serviceToken: string,
|
||||
userPoints?: number
|
||||
) {
|
||||
const {
|
||||
adults,
|
||||
@@ -696,9 +697,10 @@ export async function getSelectedRoomAvailability(
|
||||
}
|
||||
|
||||
if (Array.isArray(product)) {
|
||||
const redemptionProduct = product.find(
|
||||
(r) => r.redemption.rateCode === rateDefinition.rateCode
|
||||
)
|
||||
const redemptionProduct = userPoints ? product.find(
|
||||
(r) => r.redemption.rateCode === rateDefinition.rateCode &&
|
||||
r.redemption.localPrice.pointsPerStay <= userPoints
|
||||
) : undefined
|
||||
if (!redemptionProduct) {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user