Merged in fix/SW-3199-prod-users-are-displayed-with- (pull request #2592)

fix(SW-3199): Fixed redemption search for alternative hotels

* fix(SW-3199): Fixed redemption search for alternative hotels

* fix(SW-3199): User points validation included


Approved-by: Anton Gunnarsson
This commit is contained in:
Hrishikesh Vaipurkar
2025-08-07 07:29:32 +00:00
parent 9f4e2b3c45
commit 271d5ec32c
3 changed files with 46 additions and 5 deletions

View File

@@ -83,6 +83,7 @@ export const getHotelsByHotelIdsAvailabilityInputSchema = z
adults: z.number(),
children: z.string().optional(),
bookingCode: z.string().optional().default(""),
redemption: z.boolean().optional().default(false),
})
.refine(
(data) => {

View File

@@ -136,12 +136,40 @@ export const hotelQueryRouter = router({
env.CACHE_TIME_CITY_SEARCH
)
}),
hotelsByHotelIds: serviceProcedure
hotelsByHotelIds: safeProtectedServiceProcedure
.input(getHotelsByHotelIdsAvailabilityInputSchema)
.use(async ({ ctx, input, next }) => {
if (input.redemption) {
if (ctx.session?.token.access_token) {
const verifiedUser = await getVerifiedUser({ session: ctx.session })
if (!verifiedUser?.error) {
return next({
ctx: {
token: ctx.session.token.access_token,
userPoints: verifiedUser?.data.membership?.currentPoints ?? 0,
},
input,
})
}
}
throw unauthorizedError()
}
return next({
ctx: {
token: ctx.serviceToken,
},
input,
})
})
.query(async ({ input, ctx }) => {
const { lang } = ctx
const apiLang = toApiLang(lang)
return getHotelsAvailabilityByHotelIds(input, apiLang, ctx.serviceToken)
return getHotelsAvailabilityByHotelIds(
input,
apiLang,
ctx.token,
ctx.userPoints
)
}),
enterDetails: safeProtectedServiceProcedure

View File

@@ -796,7 +796,8 @@ export async function getHotelsAvailabilityByCity(
export async function getHotelsAvailabilityByHotelIds(
input: HotelsByHotelIdsAvailabilityInputSchema,
apiLang: string,
serviceToken: string
token: string,
userPoints: number = 0
) {
const {
hotelIds,
@@ -805,6 +806,7 @@ export async function getHotelsAvailabilityByHotelIds(
adults,
children,
bookingCode,
redemption,
} = input
const params = new URLSearchParams([
@@ -813,6 +815,7 @@ export async function getHotelsAvailabilityByHotelIds(
["adults", adults.toString()],
["children", children ?? ""],
["bookingCode", bookingCode],
["isRedemption", redemption.toString()],
["language", apiLang],
])
@@ -829,6 +832,7 @@ export async function getHotelsAvailabilityByHotelIds(
adults,
children,
bookingCode,
redemption,
})
metricsGetHotelsAvailabilityByHotelIds.start()
@@ -853,7 +857,7 @@ export async function getHotelsAvailabilityByHotelIds(
api.endpoints.v1.Availability.hotels(),
{
headers: {
Authorization: `Bearer ${serviceToken}`,
Authorization: `Bearer ${token}`,
},
},
params
@@ -873,13 +877,21 @@ export async function getHotelsAvailabilityByHotelIds(
throw badRequestError()
}
if (redemption) {
validateAvailabilityData.data.data.forEach((data) => {
data.attributes.productType?.redemptions?.forEach((r) => {
r.hasEnoughPoints = userPoints >= r.localPrice.pointsPerStay
})
})
}
return {
availability: validateAvailabilityData.data.data.flatMap(
(hotels) => hotels.attributes
),
}
},
env.CACHE_TIME_CITY_SEARCH
redemption ? "no cache" : env.CACHE_TIME_CITY_SEARCH
)
metricsGetHotelsAvailabilityByHotelIds.success()