feat: SW-2028 Implemented validation for not enough points details page

This commit is contained in:
Hrishikesh Vaipurkar
2025-03-25 15:06:12 +01:00
parent 4f4e077859
commit 13213efb29
2 changed files with 18 additions and 11 deletions

View File

@@ -657,13 +657,17 @@ export const hotelQueryRouter = router({
.use(async ({ ctx, input, next }) => { .use(async ({ ctx, input, next }) => {
if (input.redemption) { if (input.redemption) {
if (ctx.session?.token.access_token) { if (ctx.session?.token.access_token) {
const verifiedUser = await getVerifiedUser({ session: ctx.session })
if (!verifiedUser?.error) {
return next({ return next({
ctx: { ctx: {
token: ctx.session.token.access_token, token: ctx.session.token.access_token,
userPoints: verifiedUser?.data.membership?.currentPoints,
}, },
input, input,
}) })
} }
}
throw unauthorizedError() throw unauthorizedError()
} }
return next({ return next({
@@ -677,7 +681,8 @@ export const hotelQueryRouter = router({
let selectedRoomData = await getSelectedRoomAvailability( let selectedRoomData = await getSelectedRoomAvailability(
input, input,
toApiLang(ctx.lang), toApiLang(ctx.lang),
ctx.token ctx.token,
ctx.userPoints
) )
const { const {

View File

@@ -575,7 +575,8 @@ function findProduct(product: Products, rateDefinition: RateDefinition) {
export async function getSelectedRoomAvailability( export async function getSelectedRoomAvailability(
input: z.input<typeof selectedRoomAvailabilityInputSchema>, input: z.input<typeof selectedRoomAvailabilityInputSchema>,
lang: string, lang: string,
serviceToken: string serviceToken: string,
userPoints?: number
) { ) {
const { const {
adults, adults,
@@ -696,9 +697,10 @@ export async function getSelectedRoomAvailability(
} }
if (Array.isArray(product)) { if (Array.isArray(product)) {
const redemptionProduct = product.find( const redemptionProduct = userPoints ? product.find(
(r) => r.redemption.rateCode === rateDefinition.rateCode (r) => r.redemption.rateCode === rateDefinition.rateCode &&
) r.redemption.localPrice.pointsPerStay <= userPoints
) : undefined
if (!redemptionProduct) { if (!redemptionProduct) {
return null return null
} }