Merge branch 'master' into feature/tracking
This commit is contained in:
@@ -2,6 +2,15 @@ import { z } from "zod"
|
||||
|
||||
import { ChildBedTypeEnum } from "@/constants/booking"
|
||||
|
||||
const signupSchema = z.discriminatedUnion("becomeMember", [
|
||||
z.object({
|
||||
dateOfBirth: z.string(),
|
||||
postalCode: z.string(),
|
||||
becomeMember: z.literal<boolean>(true),
|
||||
}),
|
||||
z.object({ becomeMember: z.literal<boolean>(false) }),
|
||||
])
|
||||
|
||||
const roomsSchema = z.array(
|
||||
z.object({
|
||||
adults: z.number().int().nonnegative(),
|
||||
@@ -15,14 +24,17 @@ const roomsSchema = z.array(
|
||||
.default([]),
|
||||
rateCode: z.string(),
|
||||
roomTypeCode: z.coerce.string(),
|
||||
guest: z.object({
|
||||
firstName: z.string(),
|
||||
lastName: z.string(),
|
||||
email: z.string().email(),
|
||||
phoneNumber: z.string(),
|
||||
countryCode: z.string(),
|
||||
membershipNumber: z.string().optional(),
|
||||
}),
|
||||
guest: z.intersection(
|
||||
z.object({
|
||||
firstName: z.string(),
|
||||
lastName: z.string(),
|
||||
email: z.string().email(),
|
||||
phoneNumber: z.string(),
|
||||
countryCode: z.string(),
|
||||
membershipNumber: z.string().optional(),
|
||||
}),
|
||||
signupSchema
|
||||
),
|
||||
smsConfirmationRequested: z.boolean(),
|
||||
packages: z.object({
|
||||
breakfast: z.boolean(),
|
||||
@@ -30,7 +42,13 @@ const roomsSchema = z.array(
|
||||
petFriendly: z.boolean(),
|
||||
accessibility: z.boolean(),
|
||||
}),
|
||||
roomPrice: z.number().or(z.string().transform((val) => Number(val))),
|
||||
roomPrice: z.object({
|
||||
publicPrice: z.number().or(z.string().transform((val) => Number(val))),
|
||||
memberPrice: z
|
||||
.number()
|
||||
.or(z.string().transform((val) => Number(val)))
|
||||
.optional(),
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@@ -15,7 +15,18 @@ export const createBookingSchema = z
|
||||
cancellationNumber: z.string().nullable(),
|
||||
reservationStatus: z.string(),
|
||||
paymentUrl: z.string().nullable(),
|
||||
metadata: z.any(), // TODO: define metadata schema (not sure what it does)
|
||||
metadata: z
|
||||
.object({
|
||||
errorCode: z.number().optional(),
|
||||
errorMessage: z.string().optional(),
|
||||
priceChangedMetadata: z
|
||||
.object({
|
||||
roomPrice: z.number().optional(),
|
||||
totalPrice: z.number().optional(),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.nullable(),
|
||||
}),
|
||||
type: z.string(),
|
||||
id: z.string(),
|
||||
@@ -37,6 +48,7 @@ export const createBookingSchema = z
|
||||
cancellationNumber: d.data.attributes.cancellationNumber,
|
||||
reservationStatus: d.data.attributes.reservationStatus,
|
||||
paymentUrl: d.data.attributes.paymentUrl,
|
||||
metadata: d.data.attributes.metadata,
|
||||
}))
|
||||
|
||||
// QUERY
|
||||
@@ -77,7 +89,16 @@ export const bookingConfirmationSchema = z
|
||||
guest: guestSchema,
|
||||
hotelId: z.string(),
|
||||
packages: z.array(packageSchema),
|
||||
rateCode: z.string(),
|
||||
rateDefinition: z.object({
|
||||
rateCode: z.string(),
|
||||
title: z.string().nullable(),
|
||||
breakfastIncluded: z.boolean(),
|
||||
isMemberRate: z.boolean(),
|
||||
generalTerms: z.array(z.string()).optional(),
|
||||
cancellationRule: z.string().optional(),
|
||||
cancellationText: z.string().optional(),
|
||||
mustBeGuaranteed: z.boolean(),
|
||||
}),
|
||||
reservationStatus: z.string(),
|
||||
roomPrice: z.number().int(),
|
||||
roomTypeCode: z.string(),
|
||||
|
||||
@@ -8,9 +8,7 @@ export const getHotelsAvailabilityInputSchema = z.object({
|
||||
roomStayEndDate: z.string(),
|
||||
adults: z.number(),
|
||||
children: z.string().optional(),
|
||||
promotionCode: z.string().optional().default(""),
|
||||
reservationProfileType: z.string().optional().default(""),
|
||||
attachedProfileId: z.string().optional().default(""),
|
||||
bookingCode: z.string().optional().default(""),
|
||||
})
|
||||
|
||||
export const getRoomsAvailabilityInputSchema = z.object({
|
||||
@@ -19,9 +17,7 @@ export const getRoomsAvailabilityInputSchema = z.object({
|
||||
roomStayEndDate: z.string(),
|
||||
adults: z.number(),
|
||||
children: z.string().optional(),
|
||||
promotionCode: z.string().optional(),
|
||||
reservationProfileType: z.string().optional().default(""),
|
||||
attachedProfileId: z.string().optional().default(""),
|
||||
bookingCode: z.string().optional(),
|
||||
rateCode: z.string().optional(),
|
||||
})
|
||||
|
||||
@@ -31,9 +27,7 @@ export const getSelectedRoomAvailabilityInputSchema = z.object({
|
||||
roomStayEndDate: z.string(),
|
||||
adults: z.number(),
|
||||
children: z.string().optional(),
|
||||
promotionCode: z.string().optional(),
|
||||
reservationProfileType: z.string().optional().default(""),
|
||||
attachedProfileId: z.string().optional().default(""),
|
||||
bookingCode: z.string().optional(),
|
||||
rateCode: z.string(),
|
||||
roomTypeCode: z.string(),
|
||||
packageCodes: z.array(z.nativeEnum(RoomPackageCodeEnum)).optional(),
|
||||
|
||||
@@ -13,7 +13,6 @@ import { AlertTypeEnum } from "@/types/enums/alert"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
import { FacilityEnum } from "@/types/enums/facilities"
|
||||
import { PackageTypeEnum } from "@/types/enums/packages"
|
||||
import { PointOfInterestCategoryNameEnum } from "@/types/hotel"
|
||||
|
||||
const ratingsSchema = z
|
||||
.object({
|
||||
@@ -105,7 +104,7 @@ const hotelContentSchema = z.object({
|
||||
imageSizes: imageSizesSchema,
|
||||
}),
|
||||
texts: z.object({
|
||||
facilityInformation: z.string(),
|
||||
facilityInformation: z.string().optional(),
|
||||
surroundingInformation: z.string(),
|
||||
descriptions: z.object({
|
||||
short: z.string(),
|
||||
@@ -113,10 +112,10 @@ const hotelContentSchema = z.object({
|
||||
}),
|
||||
}),
|
||||
restaurantsOverviewPage: z.object({
|
||||
restaurantsOverviewPageLinkText: z.string(),
|
||||
restaurantsOverviewPageLink: z.string(),
|
||||
restaurantsContentDescriptionShort: z.string(),
|
||||
restaurantsContentDescriptionMedium: z.string(),
|
||||
restaurantsOverviewPageLinkText: z.string().optional(),
|
||||
restaurantsOverviewPageLink: z.string().optional(),
|
||||
restaurantsContentDescriptionShort: z.string().optional(),
|
||||
restaurantsContentDescriptionMedium: z.string().optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -199,14 +198,12 @@ const rewardNightSchema = z.object({
|
||||
}),
|
||||
})
|
||||
|
||||
const poiCategoryNames = z.nativeEnum(PointOfInterestCategoryNameEnum)
|
||||
|
||||
export const pointOfInterestSchema = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
distance: z.number(),
|
||||
category: z.object({
|
||||
name: poiCategoryNames,
|
||||
name: z.string(),
|
||||
group: z.string(),
|
||||
}),
|
||||
location: locationSchema,
|
||||
@@ -491,22 +488,6 @@ const occupancySchema = z.object({
|
||||
children: z.array(childrenSchema),
|
||||
})
|
||||
|
||||
const bestPricePerStaySchema = z.object({
|
||||
currency: z.string(),
|
||||
// TODO: remove optional when API is ready
|
||||
regularAmount: z.string().optional(),
|
||||
// TODO: remove optional when API is ready
|
||||
memberAmount: z.string().optional(),
|
||||
})
|
||||
|
||||
const bestPricePerNightSchema = z.object({
|
||||
currency: z.string(),
|
||||
// TODO: remove optional when API is ready
|
||||
regularAmount: z.string().optional(),
|
||||
// TODO: remove optional when API is ready
|
||||
memberAmount: z.string().optional(),
|
||||
})
|
||||
|
||||
const linksSchema = z.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
@@ -516,30 +497,6 @@ const linksSchema = z.object({
|
||||
),
|
||||
})
|
||||
|
||||
const hotelsAvailabilitySchema = z.object({
|
||||
data: z.array(
|
||||
z.object({
|
||||
attributes: z.object({
|
||||
checkInDate: z.string(),
|
||||
checkOutDate: z.string(),
|
||||
occupancy: occupancySchema.optional(),
|
||||
status: z.string(),
|
||||
hotelId: z.number(),
|
||||
ratePlanSet: z.string().optional(),
|
||||
bestPricePerStay: bestPricePerStaySchema.optional(),
|
||||
bestPricePerNight: bestPricePerNightSchema.optional(),
|
||||
}),
|
||||
relationships: linksSchema.optional(),
|
||||
type: z.string().optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export const getHotelsAvailabilitySchema = hotelsAvailabilitySchema
|
||||
export type HotelsAvailability = z.infer<typeof hotelsAvailabilitySchema>
|
||||
export type HotelsAvailabilityPrices =
|
||||
HotelsAvailability["data"][number]["attributes"]["bestPricePerNight"]
|
||||
|
||||
export const priceSchema = z.object({
|
||||
pricePerNight: z.coerce.number(),
|
||||
pricePerStay: z.coerce.number(),
|
||||
@@ -550,16 +507,53 @@ export const productTypePriceSchema = z.object({
|
||||
rateCode: z.string(),
|
||||
rateType: z.string().optional(),
|
||||
localPrice: priceSchema,
|
||||
requestedPrice: priceSchema,
|
||||
requestedPrice: priceSchema.optional(),
|
||||
})
|
||||
|
||||
const productSchema = z.object({
|
||||
productType: z.object({
|
||||
public: productTypePriceSchema,
|
||||
public: productTypePriceSchema.default({
|
||||
rateCode: "",
|
||||
rateType: "",
|
||||
localPrice: {
|
||||
currency: "SEK",
|
||||
pricePerNight: 0,
|
||||
pricePerStay: 0,
|
||||
},
|
||||
requestedPrice: undefined,
|
||||
}),
|
||||
member: productTypePriceSchema.optional(),
|
||||
}),
|
||||
})
|
||||
|
||||
const hotelsAvailabilitySchema = z.object({
|
||||
data: z.array(
|
||||
z.object({
|
||||
attributes: z.object({
|
||||
checkInDate: z.string(),
|
||||
checkOutDate: z.string(),
|
||||
occupancy: occupancySchema,
|
||||
status: z.string(),
|
||||
hotelId: z.number(),
|
||||
productType: z
|
||||
.object({
|
||||
public: productTypePriceSchema.optional(),
|
||||
member: productTypePriceSchema.optional(),
|
||||
})
|
||||
.optional(),
|
||||
}),
|
||||
relationships: linksSchema.optional(),
|
||||
type: z.string().optional(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export const getHotelsAvailabilitySchema = hotelsAvailabilitySchema
|
||||
export type HotelsAvailability = z.infer<typeof hotelsAvailabilitySchema>
|
||||
export type ProductType =
|
||||
HotelsAvailability["data"][number]["attributes"]["productType"]
|
||||
export type ProductTypePrices = z.infer<typeof productTypePriceSchema>
|
||||
|
||||
const roomConfigurationSchema = z.object({
|
||||
status: z.string(),
|
||||
roomTypeCode: z.string(),
|
||||
@@ -870,22 +864,24 @@ export const packagesSchema = z.object({
|
||||
|
||||
export const getRoomPackagesSchema = z
|
||||
.object({
|
||||
data: z.object({
|
||||
attributes: z.object({
|
||||
hotelId: z.number(),
|
||||
packages: z.array(packagesSchema).optional().default([]),
|
||||
}),
|
||||
relationships: z
|
||||
.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
url: z.string(),
|
||||
type: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.optional(),
|
||||
type: z.string(),
|
||||
}),
|
||||
data: z
|
||||
.object({
|
||||
attributes: z.object({
|
||||
hotelId: z.number(),
|
||||
packages: z.array(packagesSchema).optional().default([]),
|
||||
}),
|
||||
relationships: z
|
||||
.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
url: z.string(),
|
||||
type: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.optional(),
|
||||
type: z.string(),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.transform((data) => data.data.attributes.packages)
|
||||
.transform((data) => data.data?.attributes?.packages ?? [])
|
||||
|
||||
@@ -354,6 +354,7 @@ export const hotelQueryRouter = router({
|
||||
facilities,
|
||||
alerts: hotelAlerts,
|
||||
faq: contentstackData?.faq,
|
||||
healthFacilities: hotelAttributes.healthFacilities,
|
||||
}
|
||||
}),
|
||||
availability: router({
|
||||
@@ -368,9 +369,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
bookingCode,
|
||||
} = input
|
||||
|
||||
const params: Record<string, string | number> = {
|
||||
@@ -378,9 +377,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
...(children && { children }),
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
bookingCode,
|
||||
language: apiLang,
|
||||
}
|
||||
hotelsAvailabilityCounter.add(1, {
|
||||
@@ -389,8 +386,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.hotelsAvailability start",
|
||||
@@ -413,8 +409,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
@@ -445,8 +440,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validateAvailabilityData.error),
|
||||
})
|
||||
@@ -465,8 +459,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.hotelsAvailability success",
|
||||
@@ -475,12 +468,9 @@ export const hotelQueryRouter = router({
|
||||
})
|
||||
)
|
||||
return {
|
||||
availability: validateAvailabilityData.data.data
|
||||
.filter(
|
||||
(hotels) =>
|
||||
hotels.attributes.status === AvailabilityEnum.Available
|
||||
)
|
||||
.flatMap((hotels) => hotels.attributes),
|
||||
availability: validateAvailabilityData.data.data.flatMap(
|
||||
(hotels) => hotels.attributes
|
||||
),
|
||||
}
|
||||
}),
|
||||
rooms: serviceProcedure
|
||||
@@ -492,9 +482,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
bookingCode,
|
||||
rateCode,
|
||||
} = input
|
||||
|
||||
@@ -503,9 +491,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
...(children && { children }),
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
bookingCode,
|
||||
}
|
||||
|
||||
roomsAvailabilityCounter.add(1, {
|
||||
@@ -514,8 +500,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.roomsAvailability start",
|
||||
@@ -539,8 +524,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
@@ -571,8 +555,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validateAvailabilityData.error),
|
||||
})
|
||||
@@ -591,8 +574,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.roomsAvailability success",
|
||||
@@ -619,9 +601,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
bookingCode,
|
||||
rateCode,
|
||||
roomTypeCode,
|
||||
packageCodes,
|
||||
@@ -632,9 +612,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
...(children && { children }),
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
bookingCode,
|
||||
language: toApiLang(ctx.lang),
|
||||
}
|
||||
|
||||
@@ -644,8 +622,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.selectedRoomAvailability start",
|
||||
@@ -669,8 +646,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponseAvailability.status,
|
||||
@@ -701,8 +677,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validateAvailabilityData.error),
|
||||
})
|
||||
@@ -750,9 +725,13 @@ export const hotelQueryRouter = router({
|
||||
return null
|
||||
}
|
||||
|
||||
const rateDetails = validateAvailabilityData.data.rateDefinitions.find(
|
||||
(rateDef) => rateDef.rateCode === rateCode
|
||||
)?.generalTerms
|
||||
|
||||
const rateTypes = selectedRoom.products.find(
|
||||
(rate) =>
|
||||
rate.productType.public.rateCode === rateCode ||
|
||||
rate.productType.public?.rateCode === rateCode ||
|
||||
rate.productType.member?.rateCode === rateCode
|
||||
)
|
||||
|
||||
@@ -796,8 +775,7 @@ export const hotelQueryRouter = router({
|
||||
roomStayEndDate,
|
||||
adults,
|
||||
children,
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
bookingCode,
|
||||
})
|
||||
console.info(
|
||||
"api.hotels.selectedRoomAvailability success",
|
||||
@@ -808,6 +786,7 @@ export const hotelQueryRouter = router({
|
||||
|
||||
return {
|
||||
selectedRoom,
|
||||
rateDetails,
|
||||
mustBeGuaranteed,
|
||||
cancellationText,
|
||||
memberRate: rates?.member,
|
||||
@@ -960,12 +939,10 @@ export const hotelQueryRouter = router({
|
||||
"api.hotels.packages error",
|
||||
JSON.stringify({ query: { hotelId, params } })
|
||||
)
|
||||
throw serverErrorByStatus(apiResponse.status, apiResponse)
|
||||
}
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
const validatedPackagesData = getRoomPackagesSchema.safeParse(apiJson)
|
||||
|
||||
if (!validatedPackagesData.success) {
|
||||
getHotelFailCounter.add(1, {
|
||||
hotelId,
|
||||
|
||||
62
server/routers/hotels/schemas/packages.ts
Normal file
62
server/routers/hotels/schemas/packages.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||
import { CurrencyEnum } from "@/types/enums/currency"
|
||||
|
||||
export const getRoomPackagesInputSchema = z.object({
|
||||
hotelId: z.string(),
|
||||
startDate: z.string(),
|
||||
endDate: z.string(),
|
||||
adults: z.number(),
|
||||
children: z.number().optional().default(0),
|
||||
packageCodes: z.array(z.string()).optional().default([]),
|
||||
})
|
||||
|
||||
export const packagePriceSchema = z
|
||||
.object({
|
||||
currency: z.nativeEnum(CurrencyEnum),
|
||||
price: z.string(),
|
||||
totalPrice: z.string(),
|
||||
})
|
||||
.optional()
|
||||
.default({
|
||||
currency: CurrencyEnum.SEK,
|
||||
price: "0",
|
||||
totalPrice: "0",
|
||||
}) // TODO: Remove optional and default when the API change has been deployed
|
||||
|
||||
export const packagesSchema = z.object({
|
||||
code: z.nativeEnum(RoomPackageCodeEnum),
|
||||
description: z.string(),
|
||||
localPrice: packagePriceSchema,
|
||||
requestedPrice: packagePriceSchema,
|
||||
inventories: z.array(
|
||||
z.object({
|
||||
date: z.string(),
|
||||
total: z.number(),
|
||||
available: z.number(),
|
||||
})
|
||||
),
|
||||
})
|
||||
|
||||
export const getRoomPackagesSchema = z
|
||||
.object({
|
||||
data: z.object({
|
||||
attributes: z.object({
|
||||
hotelId: z.number(),
|
||||
packages: z.array(packagesSchema).default([]),
|
||||
}),
|
||||
relationships: z
|
||||
.object({
|
||||
links: z.array(
|
||||
z.object({
|
||||
url: z.string(),
|
||||
type: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.optional(),
|
||||
type: z.string(),
|
||||
}),
|
||||
})
|
||||
.transform((data) => data.data.attributes.packages)
|
||||
@@ -11,8 +11,8 @@ const roomContentSchema = z.object({
|
||||
),
|
||||
texts: z.object({
|
||||
descriptions: z.object({
|
||||
short: z.string(),
|
||||
medium: z.string(),
|
||||
short: z.string().optional(),
|
||||
medium: z.string().optional(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -13,38 +13,33 @@ import {
|
||||
} from "./output"
|
||||
|
||||
import type { RequestOptionsWithOutBody } from "@/types/fetch"
|
||||
import {
|
||||
PointOfInterestCategoryNameEnum,
|
||||
PointOfInterestGroupEnum,
|
||||
} from "@/types/hotel"
|
||||
import { PointOfInterestGroupEnum } from "@/types/hotel"
|
||||
import { HotelLocation } from "@/types/trpc/routers/hotel/locations"
|
||||
import type { Lang } from "@/constants/languages"
|
||||
import type { Endpoint } from "@/lib/api/endpoints"
|
||||
|
||||
export function getPoiGroupByCategoryName(
|
||||
category: PointOfInterestCategoryNameEnum
|
||||
) {
|
||||
export function getPoiGroupByCategoryName(category: string) {
|
||||
switch (category) {
|
||||
case PointOfInterestCategoryNameEnum.AIRPORT:
|
||||
case PointOfInterestCategoryNameEnum.BUS_TERMINAL:
|
||||
case PointOfInterestCategoryNameEnum.TRANSPORTATIONS:
|
||||
case "Airport":
|
||||
case "Bus terminal":
|
||||
case "Transportations":
|
||||
return PointOfInterestGroupEnum.PUBLIC_TRANSPORT
|
||||
case PointOfInterestCategoryNameEnum.AMUSEMENT_PARK:
|
||||
case PointOfInterestCategoryNameEnum.MUSEUM:
|
||||
case PointOfInterestCategoryNameEnum.SPORTS:
|
||||
case PointOfInterestCategoryNameEnum.THEATRE:
|
||||
case PointOfInterestCategoryNameEnum.TOURIST:
|
||||
case PointOfInterestCategoryNameEnum.ZOO:
|
||||
case "Amusement park":
|
||||
case "Museum":
|
||||
case "Sports":
|
||||
case "Theatre":
|
||||
case "Tourist":
|
||||
case "Zoo":
|
||||
return PointOfInterestGroupEnum.ATTRACTIONS
|
||||
case PointOfInterestCategoryNameEnum.NEARBY_COMPANIES:
|
||||
case PointOfInterestCategoryNameEnum.FAIR:
|
||||
case "Nearby companies":
|
||||
case "Fair":
|
||||
return PointOfInterestGroupEnum.BUSINESS
|
||||
case PointOfInterestCategoryNameEnum.PARKING_GARAGE:
|
||||
case "Parking / Garage":
|
||||
return PointOfInterestGroupEnum.PARKING
|
||||
case PointOfInterestCategoryNameEnum.SHOPPING:
|
||||
case PointOfInterestCategoryNameEnum.RESTAURANT:
|
||||
case "Shopping":
|
||||
case "Restaurant":
|
||||
return PointOfInterestGroupEnum.SHOPPING_DINING
|
||||
case PointOfInterestCategoryNameEnum.HOSPITAL:
|
||||
case "Hospital":
|
||||
default:
|
||||
return PointOfInterestGroupEnum.LOCATION
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
|
||||
import { signUpSchema } from "@/components/Forms/Signup/schema"
|
||||
|
||||
// Query
|
||||
export const staysInput = z
|
||||
.object({
|
||||
@@ -35,3 +39,19 @@ export const saveCreditCardInput = z.object({
|
||||
transactionId: z.string(),
|
||||
merchantId: z.string().optional(),
|
||||
})
|
||||
|
||||
export const signupInput = signUpSchema
|
||||
.extend({
|
||||
language: z.nativeEnum(Lang),
|
||||
})
|
||||
.omit({ termsAccepted: true })
|
||||
.transform((data) => ({
|
||||
...data,
|
||||
phoneNumber: data.phoneNumber.replace(/\s+/g, ""),
|
||||
address: {
|
||||
...data.address,
|
||||
city: "",
|
||||
country: "",
|
||||
streetAddress: "",
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import { metrics } from "@opentelemetry/api"
|
||||
|
||||
import { signupVerify } from "@/constants/routes/signup"
|
||||
import { env } from "@/env/server"
|
||||
import * as api from "@/lib/api"
|
||||
import { serverErrorByStatus } from "@/server/errors/trpc"
|
||||
import {
|
||||
initiateSaveCardSchema,
|
||||
subscriberIdSchema,
|
||||
} from "@/server/routers/user/output"
|
||||
import { protectedProcedure, router } from "@/server/trpc"
|
||||
import { protectedProcedure, router, serviceProcedure } from "@/server/trpc"
|
||||
|
||||
import {
|
||||
addCreditCardInput,
|
||||
deleteCreditCardInput,
|
||||
saveCreditCardInput,
|
||||
signupInput,
|
||||
} from "./input"
|
||||
|
||||
const meter = metrics.getMeter("trpc.user")
|
||||
@@ -24,6 +27,9 @@ const generatePreferencesLinkSuccessCounter = meter.createCounter(
|
||||
const generatePreferencesLinkFailCounter = meter.createCounter(
|
||||
"trpc.user.generatePreferencesLink-fail"
|
||||
)
|
||||
const signupCounter = meter.createCounter("trpc.user.signup")
|
||||
const signupSuccessCounter = meter.createCounter("trpc.user.signup-success")
|
||||
const signupFailCounter = meter.createCounter("trpc.user.signup-fail")
|
||||
|
||||
export const userMutationRouter = router({
|
||||
creditCard: router({
|
||||
@@ -208,4 +214,46 @@ export const userMutationRouter = router({
|
||||
generatePreferencesLinkSuccessCounter.add(1)
|
||||
return preferencesLink.toString()
|
||||
}),
|
||||
signup: serviceProcedure.input(signupInput).mutation(async function ({
|
||||
ctx,
|
||||
input,
|
||||
}) {
|
||||
signupCounter.add(1)
|
||||
|
||||
const apiResponse = await api.post(api.endpoints.v1.Profile.profile, {
|
||||
body: input,
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
signupFailCounter.add(1, {
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
error: text,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.user.signup api error",
|
||||
JSON.stringify({
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
error: text,
|
||||
},
|
||||
})
|
||||
)
|
||||
throw serverErrorByStatus(apiResponse.status, text)
|
||||
}
|
||||
signupSuccessCounter.add(1)
|
||||
console.info("api.user.signup success")
|
||||
return {
|
||||
success: true,
|
||||
redirectUrl: signupVerify[input.language],
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { countriesMap } from "@/components/TempDesignSystem/Form/Country/countries"
|
||||
import { passwordValidator } from "@/utils/passwordValidator"
|
||||
import { phoneValidator } from "@/utils/phoneValidator"
|
||||
import { getMembership } from "@/utils/user"
|
||||
|
||||
export const membershipSchema = z.object({
|
||||
|
||||
@@ -2,6 +2,7 @@ import { metrics } from "@opentelemetry/api"
|
||||
import { cache } from "react"
|
||||
|
||||
import * as api from "@/lib/api"
|
||||
import { dt } from "@/lib/dt"
|
||||
import {
|
||||
protectedProcedure,
|
||||
router,
|
||||
@@ -208,7 +209,13 @@ export function parsedUser(data: User, isMFA: boolean) {
|
||||
return user
|
||||
}
|
||||
|
||||
async function getCreditCards(session: Session) {
|
||||
async function getCreditCards({
|
||||
session,
|
||||
onlyNonExpired,
|
||||
}: {
|
||||
session: Session
|
||||
onlyNonExpired?: boolean
|
||||
}) {
|
||||
getCreditCardsCounter.add(1)
|
||||
console.info("api.profile.creditCards start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v1.Profile.creditCards, {
|
||||
@@ -255,7 +262,19 @@ async function getCreditCards(session: Session) {
|
||||
}
|
||||
getCreditCardsSuccessCounter.add(1)
|
||||
console.info("api.profile.creditCards success", JSON.stringify({}))
|
||||
return verifiedData.data.data
|
||||
|
||||
return verifiedData.data.data.filter((card) => {
|
||||
if (onlyNonExpired) {
|
||||
try {
|
||||
const expirationDate = dt(card.expirationDate).startOf("day")
|
||||
const currentDate = dt().startOf("day")
|
||||
return expirationDate > currentDate
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
export const userQueryRouter = router({
|
||||
@@ -730,14 +749,14 @@ export const userQueryRouter = router({
|
||||
}),
|
||||
|
||||
creditCards: protectedProcedure.query(async function ({ ctx }) {
|
||||
return await getCreditCards(ctx.session)
|
||||
return await getCreditCards({ session: ctx.session })
|
||||
}),
|
||||
safeCreditCards: safeProtectedProcedure.query(async function ({ ctx }) {
|
||||
if (!ctx.session) {
|
||||
return null
|
||||
}
|
||||
|
||||
return await getCreditCards(ctx.session)
|
||||
return await getCreditCards({ session: ctx.session, onlyNonExpired: true })
|
||||
}),
|
||||
|
||||
membershipCards: protectedProcedure.query(async function ({ ctx }) {
|
||||
|
||||
Reference in New Issue
Block a user