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:
@@ -83,6 +83,7 @@ export const getHotelsByHotelIdsAvailabilityInputSchema = z
|
|||||||
adults: z.number(),
|
adults: z.number(),
|
||||||
children: z.string().optional(),
|
children: z.string().optional(),
|
||||||
bookingCode: z.string().optional().default(""),
|
bookingCode: z.string().optional().default(""),
|
||||||
|
redemption: z.boolean().optional().default(false),
|
||||||
})
|
})
|
||||||
.refine(
|
.refine(
|
||||||
(data) => {
|
(data) => {
|
||||||
|
|||||||
@@ -136,12 +136,40 @@ export const hotelQueryRouter = router({
|
|||||||
env.CACHE_TIME_CITY_SEARCH
|
env.CACHE_TIME_CITY_SEARCH
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
hotelsByHotelIds: serviceProcedure
|
hotelsByHotelIds: safeProtectedServiceProcedure
|
||||||
.input(getHotelsByHotelIdsAvailabilityInputSchema)
|
.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 }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const { lang } = ctx
|
const { lang } = ctx
|
||||||
const apiLang = toApiLang(lang)
|
const apiLang = toApiLang(lang)
|
||||||
return getHotelsAvailabilityByHotelIds(input, apiLang, ctx.serviceToken)
|
return getHotelsAvailabilityByHotelIds(
|
||||||
|
input,
|
||||||
|
apiLang,
|
||||||
|
ctx.token,
|
||||||
|
ctx.userPoints
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
enterDetails: safeProtectedServiceProcedure
|
enterDetails: safeProtectedServiceProcedure
|
||||||
|
|||||||
@@ -796,7 +796,8 @@ export async function getHotelsAvailabilityByCity(
|
|||||||
export async function getHotelsAvailabilityByHotelIds(
|
export async function getHotelsAvailabilityByHotelIds(
|
||||||
input: HotelsByHotelIdsAvailabilityInputSchema,
|
input: HotelsByHotelIdsAvailabilityInputSchema,
|
||||||
apiLang: string,
|
apiLang: string,
|
||||||
serviceToken: string
|
token: string,
|
||||||
|
userPoints: number = 0
|
||||||
) {
|
) {
|
||||||
const {
|
const {
|
||||||
hotelIds,
|
hotelIds,
|
||||||
@@ -805,6 +806,7 @@ export async function getHotelsAvailabilityByHotelIds(
|
|||||||
adults,
|
adults,
|
||||||
children,
|
children,
|
||||||
bookingCode,
|
bookingCode,
|
||||||
|
redemption,
|
||||||
} = input
|
} = input
|
||||||
|
|
||||||
const params = new URLSearchParams([
|
const params = new URLSearchParams([
|
||||||
@@ -813,6 +815,7 @@ export async function getHotelsAvailabilityByHotelIds(
|
|||||||
["adults", adults.toString()],
|
["adults", adults.toString()],
|
||||||
["children", children ?? ""],
|
["children", children ?? ""],
|
||||||
["bookingCode", bookingCode],
|
["bookingCode", bookingCode],
|
||||||
|
["isRedemption", redemption.toString()],
|
||||||
["language", apiLang],
|
["language", apiLang],
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -829,6 +832,7 @@ export async function getHotelsAvailabilityByHotelIds(
|
|||||||
adults,
|
adults,
|
||||||
children,
|
children,
|
||||||
bookingCode,
|
bookingCode,
|
||||||
|
redemption,
|
||||||
})
|
})
|
||||||
|
|
||||||
metricsGetHotelsAvailabilityByHotelIds.start()
|
metricsGetHotelsAvailabilityByHotelIds.start()
|
||||||
@@ -853,7 +857,7 @@ export async function getHotelsAvailabilityByHotelIds(
|
|||||||
api.endpoints.v1.Availability.hotels(),
|
api.endpoints.v1.Availability.hotels(),
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${serviceToken}`,
|
Authorization: `Bearer ${token}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
params
|
params
|
||||||
@@ -873,13 +877,21 @@ export async function getHotelsAvailabilityByHotelIds(
|
|||||||
throw badRequestError()
|
throw badRequestError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (redemption) {
|
||||||
|
validateAvailabilityData.data.data.forEach((data) => {
|
||||||
|
data.attributes.productType?.redemptions?.forEach((r) => {
|
||||||
|
r.hasEnoughPoints = userPoints >= r.localPrice.pointsPerStay
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
availability: validateAvailabilityData.data.data.flatMap(
|
availability: validateAvailabilityData.data.data.flatMap(
|
||||||
(hotels) => hotels.attributes
|
(hotels) => hotels.attributes
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
env.CACHE_TIME_CITY_SEARCH
|
redemption ? "no cache" : env.CACHE_TIME_CITY_SEARCH
|
||||||
)
|
)
|
||||||
|
|
||||||
metricsGetHotelsAvailabilityByHotelIds.success()
|
metricsGetHotelsAvailabilityByHotelIds.success()
|
||||||
|
|||||||
Reference in New Issue
Block a user