feat: SW-1583 Implemented Reward nights on city search
This commit is contained in:
@@ -13,6 +13,7 @@ export const hotelsAvailabilityInputSchema = z.object({
|
||||
adults: z.number(),
|
||||
children: z.string().optional(),
|
||||
bookingCode: z.string().optional().default(""),
|
||||
redemption: z.boolean().optional().default(false),
|
||||
})
|
||||
|
||||
export const getHotelsByHotelIdsAvailabilityInputSchema = z.object({
|
||||
|
||||
@@ -7,6 +7,7 @@ import { dt } from "@/lib/dt"
|
||||
import { badRequestError } from "@/server/errors/trpc"
|
||||
import {
|
||||
contentStackBaseWithServiceProcedure,
|
||||
protectedProcedure,
|
||||
publicProcedure,
|
||||
router,
|
||||
safeProtectedServiceProcedure,
|
||||
@@ -215,7 +216,7 @@ export const getHotel = cache(
|
||||
export const getHotelsAvailabilityByCity = async (
|
||||
input: HotelsAvailabilityInputSchema,
|
||||
apiLang: string,
|
||||
serviceToken: string
|
||||
token: string // Either service token or user access token in case of redemption search
|
||||
) => {
|
||||
const {
|
||||
cityId,
|
||||
@@ -224,6 +225,7 @@ export const getHotelsAvailabilityByCity = async (
|
||||
adults,
|
||||
children,
|
||||
bookingCode,
|
||||
redemption,
|
||||
} = input
|
||||
|
||||
const params: Record<string, string | number> = {
|
||||
@@ -232,6 +234,7 @@ export const getHotelsAvailabilityByCity = async (
|
||||
adults,
|
||||
...(children && { children }),
|
||||
...(bookingCode && { bookingCode }),
|
||||
...(redemption ? { isRedemption: "true" } : {}),
|
||||
language: apiLang,
|
||||
}
|
||||
metrics.hotelsAvailability.counter.add(1, {
|
||||
@@ -241,6 +244,7 @@ export const getHotelsAvailabilityByCity = async (
|
||||
adults,
|
||||
children,
|
||||
bookingCode,
|
||||
redemption,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.hotelsAvailability start",
|
||||
@@ -251,7 +255,7 @@ export const getHotelsAvailabilityByCity = async (
|
||||
{
|
||||
cache: undefined,
|
||||
headers: {
|
||||
Authorization: `Bearer ${serviceToken}`,
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
next: {
|
||||
revalidate: env.CACHE_TIME_CITY_SEARCH,
|
||||
@@ -268,6 +272,7 @@ export const getHotelsAvailabilityByCity = async (
|
||||
adults,
|
||||
children,
|
||||
bookingCode,
|
||||
redemption,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
@@ -298,6 +303,7 @@ export const getHotelsAvailabilityByCity = async (
|
||||
adults,
|
||||
children,
|
||||
bookingCode,
|
||||
redemption,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validateAvailabilityData.error),
|
||||
})
|
||||
@@ -317,6 +323,7 @@ export const getHotelsAvailabilityByCity = async (
|
||||
adults,
|
||||
children,
|
||||
bookingCode,
|
||||
redemption,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.hotelsAvailability success",
|
||||
@@ -466,6 +473,17 @@ export const hotelQueryRouter = router({
|
||||
const apiLang = toApiLang(lang)
|
||||
return getHotelsAvailabilityByCity(input, apiLang, ctx.serviceToken)
|
||||
}),
|
||||
hotelsByCityWithRedemption: protectedProcedure
|
||||
.input(hotelsAvailabilityInputSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { lang } = ctx
|
||||
const apiLang = toApiLang(lang)
|
||||
return getHotelsAvailabilityByCity(
|
||||
input,
|
||||
apiLang,
|
||||
ctx.session.token.access_token
|
||||
)
|
||||
}),
|
||||
hotelsByHotelIds: serviceProcedure
|
||||
.input(getHotelsByHotelIdsAvailabilityInputSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { productTypePriceSchema } from "../productTypePrice"
|
||||
import {
|
||||
productTypePriceSchema,
|
||||
productTypePointsSchema,
|
||||
} from "../productTypePrice"
|
||||
|
||||
export const productTypeSchema = z
|
||||
.object({
|
||||
public: productTypePriceSchema.optional(),
|
||||
member: productTypePriceSchema.optional(),
|
||||
redemption: productTypePointsSchema.optional(),
|
||||
redemptionA: productTypePointsSchema.optional(),
|
||||
redemptionB: productTypePointsSchema.optional(),
|
||||
})
|
||||
.optional()
|
||||
|
||||
@@ -10,9 +10,24 @@ export const priceSchema = z.object({
|
||||
regularPricePerStay: z.coerce.number().optional(),
|
||||
})
|
||||
|
||||
export const productTypePriceSchema = z.object({
|
||||
localPrice: priceSchema,
|
||||
export const pointsSchema = z.object({
|
||||
currency: z.nativeEnum(CurrencyEnum).optional(),
|
||||
pricePerNight: z.coerce.number().optional(),
|
||||
pricePerStay: z.coerce.number().optional(),
|
||||
pointsPerNight: z.number(),
|
||||
pointsPerStay: z.number(),
|
||||
})
|
||||
|
||||
const partialPriceSchema = z.object({
|
||||
rateCode: z.string(),
|
||||
rateType: z.string().optional(),
|
||||
requestedPrice: priceSchema.optional(),
|
||||
})
|
||||
|
||||
export const productTypePriceSchema = partialPriceSchema.extend({
|
||||
localPrice: priceSchema,
|
||||
})
|
||||
|
||||
export const productTypePointsSchema = partialPriceSchema.extend({
|
||||
localPrice: pointsSchema,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user