fix(SW-188): use camelCase for schemas

This commit is contained in:
Chuma McPhoy
2024-08-19 10:22:59 +02:00
parent aa38e82698
commit 16e0165a6e
3 changed files with 80 additions and 80 deletions

View File

@@ -2,7 +2,7 @@ import { z } from "zod"
import { toLang } from "@/server/utils" import { toLang } from "@/server/utils"
const RatingsSchema = z const ratingsSchema = z
.object({ .object({
tripAdvisor: z.object({ tripAdvisor: z.object({
numberOfReviews: z.number(), numberOfReviews: z.number(),
@@ -28,63 +28,63 @@ const RatingsSchema = z
}) })
.optional() .optional()
const AddressSchema = z.object({ const addressSchema = z.object({
streetAddress: z.string(), streetAddress: z.string(),
city: z.string(), city: z.string(),
zipCode: z.string(), zipCode: z.string(),
country: z.string(), country: z.string(),
}) })
const ContactInformationSchema = z.object({ const contactInformationSchema = z.object({
phoneNumber: z.string(), phoneNumber: z.string(),
faxNumber: z.string().optional(), faxNumber: z.string().optional(),
email: z.string(), email: z.string(),
websiteUrl: z.string(), websiteUrl: z.string(),
}) })
const CheckinSchema = z.object({ const checkinSchema = z.object({
checkInTime: z.string(), checkInTime: z.string(),
checkOutTime: z.string(), checkOutTime: z.string(),
onlineCheckOutAvailableFrom: z.string().nullable().optional(), onlineCheckOutAvailableFrom: z.string().nullable().optional(),
onlineCheckout: z.boolean(), onlineCheckout: z.boolean(),
}) })
const EcoLabelsSchema = z.object({ const ecoLabelsSchema = z.object({
euEcoLabel: z.boolean(), euEcoLabel: z.boolean(),
greenGlobeLabel: z.boolean(), greenGlobeLabel: z.boolean(),
nordicEcoLabel: z.boolean(), nordicEcoLabel: z.boolean(),
svanenEcoLabelCertificateNumber: z.string().optional(), svanenEcoLabelCertificateNumber: z.string().optional(),
}) })
const HotelFacilityDetailSchema = z.object({ const hotelFacilityDetailSchema = z.object({
heading: z.string(), heading: z.string(),
description: z.string(), description: z.string(),
}) })
const HotelFacilitySchema = z.object({ const hotelFacilitySchema = z.object({
breakfast: HotelFacilityDetailSchema, breakfast: hotelFacilityDetailSchema,
checkout: HotelFacilityDetailSchema, checkout: hotelFacilityDetailSchema,
gym: HotelFacilityDetailSchema, gym: hotelFacilityDetailSchema,
internet: HotelFacilityDetailSchema, internet: hotelFacilityDetailSchema,
laundry: HotelFacilityDetailSchema, laundry: hotelFacilityDetailSchema,
luggage: HotelFacilityDetailSchema, luggage: hotelFacilityDetailSchema,
shop: HotelFacilityDetailSchema, shop: hotelFacilityDetailSchema,
telephone: HotelFacilityDetailSchema, telephone: hotelFacilityDetailSchema,
}) })
const HotelInformationDetailSchema = z.object({ const hotelInformationDetailSchema = z.object({
heading: z.string(), heading: z.string(),
description: z.string(), description: z.string(),
link: z.string().optional(), link: z.string().optional(),
}) })
const HotelInformationSchema = z.object({ const hotelInformationSchema = z.object({
accessibility: HotelInformationDetailSchema, accessibility: hotelInformationDetailSchema,
safety: HotelInformationDetailSchema, safety: hotelInformationDetailSchema,
sustainability: HotelInformationDetailSchema, sustainability: hotelInformationDetailSchema,
}) })
const InteriorSchema = z.object({ const interiorSchema = z.object({
numberOfBeds: z.number(), numberOfBeds: z.number(),
numberOfCribs: z.number(), numberOfCribs: z.number(),
numberOfFloors: z.number(), numberOfFloors: z.number(),
@@ -99,37 +99,37 @@ const InteriorSchema = z.object({
}), }),
}) })
const ReceptionHoursSchema = z.object({ const receptionHoursSchema = z.object({
alwaysOpen: z.boolean(), alwaysOpen: z.boolean(),
isClosed: z.boolean(), isClosed: z.boolean(),
openingTime: z.string().optional(), openingTime: z.string().optional(),
closingTime: z.string().optional(), closingTime: z.string().optional(),
}) })
const LocationSchema = z.object({ const locationSchema = z.object({
distanceToCentre: z.number(), distanceToCentre: z.number(),
latitude: z.number(), latitude: z.number(),
longitude: z.number(), longitude: z.number(),
}) })
const ImageMetaDataSchema = z.object({ const imageMetaDataSchema = z.object({
title: z.string(), title: z.string(),
altText: z.string(), altText: z.string(),
altText_En: z.string(), altText_En: z.string(),
copyRight: z.string(), copyRight: z.string(),
}) })
const ImageSizesSchema = z.object({ const imageSizesSchema = z.object({
tiny: z.string(), tiny: z.string(),
small: z.string(), small: z.string(),
medium: z.string(), medium: z.string(),
large: z.string(), large: z.string(),
}) })
const HotelContentSchema = z.object({ const hotelContentSchema = z.object({
images: z.object({ images: z.object({
metaData: ImageMetaDataSchema, metaData: imageMetaDataSchema,
imageSizes: ImageSizesSchema, imageSizes: imageSizesSchema,
}), }),
texts: z.object({ texts: z.object({
facilityInformation: z.string(), facilityInformation: z.string(),
@@ -147,7 +147,7 @@ const HotelContentSchema = z.object({
}), }),
}) })
const DetailedFacilitySchema = z.object({ const detailedFacilitySchema = z.object({
id: z.number(), id: z.number(),
name: z.string(), name: z.string(),
code: z.string().optional(), code: z.string().optional(),
@@ -158,13 +158,13 @@ const DetailedFacilitySchema = z.object({
sortOrder: z.number(), sortOrder: z.number(),
}) })
const HealthFacilitySchema = z.object({ const healthFacilitySchema = z.object({
type: z.string(), type: z.string(),
content: z.object({ content: z.object({
images: z.array( images: z.array(
z.object({ z.object({
metaData: ImageMetaDataSchema, metaData: imageMetaDataSchema,
imageSizes: ImageSizesSchema, imageSizes: imageSizesSchema,
}) })
), ),
texts: z.object({ texts: z.object({
@@ -205,7 +205,7 @@ const HealthFacilitySchema = z.object({
), ),
}) })
const RewardNightSchema = z.object({ const rewardNightSchema = z.object({
points: z.number(), points: z.number(),
campaign: z.object({ campaign: z.object({
start: z.string(), start: z.string(),
@@ -214,18 +214,18 @@ const RewardNightSchema = z.object({
}), }),
}) })
const PointsOfInterestSchema = z.object({ const pointsOfInterestSchema = z.object({
name: z.string(), name: z.string(),
distance: z.number(), distance: z.number(),
category: z.object({ category: z.object({
name: z.string(), name: z.string(),
group: z.string(), group: z.string(),
}), }),
location: LocationSchema, location: locationSchema,
isHighlighted: z.boolean(), isHighlighted: z.boolean(),
}) })
const ParkingPricingSchema = z.object({ const parkingPricingSchema = z.object({
freeParking: z.boolean(), freeParking: z.boolean(),
paymentType: z.string(), paymentType: z.string(),
localCurrency: z.object({ localCurrency: z.object({
@@ -278,7 +278,7 @@ const ParkingPricingSchema = z.object({
.optional(), .optional(),
}) })
const ParkingSchema = z.object({ const parkingSchema = z.object({
type: z.string(), type: z.string(),
name: z.string(), name: z.string(),
address: z.string(), address: z.string(),
@@ -286,25 +286,25 @@ const ParkingSchema = z.object({
numberOfChargingSpaces: z.number(), numberOfChargingSpaces: z.number(),
distanceToHotel: z.number(), distanceToHotel: z.number(),
canMakeReservation: z.boolean(), canMakeReservation: z.boolean(),
pricing: ParkingPricingSchema, pricing: parkingPricingSchema,
}) })
const SpecialNeedSchema = z.object({ const specialNeedSchema = z.object({
name: z.string(), name: z.string(),
details: z.string(), details: z.string(),
}) })
const SpecialNeedGroupSchema = z.object({ const specialNeedGroupSchema = z.object({
name: z.string(), name: z.string(),
specialNeeds: z.array(SpecialNeedSchema), specialNeeds: z.array(specialNeedSchema),
}) })
const SocialMediaSchema = z.object({ const socialMediaSchema = z.object({
instagram: z.string().optional(), instagram: z.string().optional(),
facebook: z.string().optional(), facebook: z.string().optional(),
}) })
const MetaSpecialAlertSchema = z.object({ const metaSpecialAlertSchema = z.object({
type: z.string(), type: z.string(),
description: z.string().optional(), description: z.string().optional(),
displayInBookingFlow: z.boolean(), displayInBookingFlow: z.boolean(),
@@ -312,11 +312,11 @@ const MetaSpecialAlertSchema = z.object({
endDate: z.string(), endDate: z.string(),
}) })
const MetaSchema = z.object({ const metaSchema = z.object({
specialAlerts: z.array(MetaSpecialAlertSchema), specialAlerts: z.array(metaSpecialAlertSchema),
}) })
const RelationshipsSchema = z.object({ const relationshipsSchema = z.object({
restaurants: z.object({ restaurants: z.object({
links: z.object({ links: z.object({
related: z.string(), related: z.string(),
@@ -339,11 +339,11 @@ const RelationshipsSchema = z.object({
}), }),
}) })
const RoomContentSchema = z.object({ const roomContentSchema = z.object({
images: z.array( images: z.array(
z.object({ z.object({
metaData: ImageMetaDataSchema, metaData: imageMetaDataSchema,
imageSizes: ImageSizesSchema, imageSizes: imageSizesSchema,
}) })
), ),
texts: z.object({ texts: z.object({
@@ -354,7 +354,7 @@ const RoomContentSchema = z.object({
}), }),
}) })
const RoomTypesSchema = z.object({ const roomTypesSchema = z.object({
name: z.string(), name: z.string(),
description: z.string(), description: z.string(),
code: z.string(), code: z.string(),
@@ -388,20 +388,20 @@ const RoomTypesSchema = z.object({
isLackingExtraBeds: z.boolean(), isLackingExtraBeds: z.boolean(),
}) })
const RoomFacilitiesSchema = z.object({ const roomFacilitiesSchema = z.object({
availableInAllRooms: z.boolean(), availableInAllRooms: z.boolean(),
name: z.string(), name: z.string(),
isUniqueSellingPoint: z.boolean(), isUniqueSellingPoint: z.boolean(),
sortOrder: z.number(), sortOrder: z.number(),
}) })
export const RoomSchema = z.object({ export const roomSchema = z.object({
attributes: z.object({ attributes: z.object({
name: z.string(), name: z.string(),
sortOrder: z.number(), sortOrder: z.number(),
content: RoomContentSchema, content: roomContentSchema,
roomTypes: z.array(RoomTypesSchema), roomTypes: z.array(roomTypesSchema),
roomFacilities: z.array(RoomFacilitiesSchema), roomFacilities: z.array(roomFacilitiesSchema),
occupancy: z.object({ occupancy: z.object({
total: z.number(), total: z.number(),
adults: z.number(), adults: z.number(),
@@ -440,35 +440,35 @@ export const getHotelDataSchema = z.object({
isPublished: z.boolean(), isPublished: z.boolean(),
cityId: z.string(), cityId: z.string(),
cityName: z.string(), cityName: z.string(),
ratings: RatingsSchema, ratings: ratingsSchema,
address: AddressSchema, address: addressSchema,
contactInformation: ContactInformationSchema, contactInformation: contactInformationSchema,
hotelFacts: z.object({ hotelFacts: z.object({
checkin: CheckinSchema, checkin: checkinSchema,
ecoLabels: EcoLabelsSchema, ecoLabels: ecoLabelsSchema,
hotelFacilityDetail: HotelFacilitySchema, hotelFacilityDetail: hotelFacilitySchema,
hotelInformation: HotelInformationSchema, hotelInformation: hotelInformationSchema,
interior: InteriorSchema, interior: interiorSchema,
receptionHours: ReceptionHoursSchema, receptionHours: receptionHoursSchema,
yearBuilt: z.string(), yearBuilt: z.string(),
}), }),
location: LocationSchema, location: locationSchema,
hotelContent: HotelContentSchema, hotelContent: hotelContentSchema,
detailedFacilities: z.array(DetailedFacilitySchema), detailedFacilities: z.array(detailedFacilitySchema),
healthFacilities: z.array(HealthFacilitySchema), healthFacilities: z.array(healthFacilitySchema),
rewardNight: RewardNightSchema, rewardNight: rewardNightSchema,
pointsOfInterest: z.array(PointsOfInterestSchema), pointsOfInterest: z.array(pointsOfInterestSchema),
parking: z.array(ParkingSchema), parking: z.array(parkingSchema),
specialNeedGroups: z.array(SpecialNeedGroupSchema), specialNeedGroups: z.array(specialNeedGroupSchema),
socialMedia: SocialMediaSchema, socialMedia: socialMediaSchema,
meta: MetaSchema.optional(), meta: metaSchema.optional(),
isActive: z.boolean(), isActive: z.boolean(),
}), }),
relationships: RelationshipsSchema, relationships: relationshipsSchema,
}), }),
// NOTE: We can pass an "include" param to the hotel API to retrieve // NOTE: We can pass an "include" param to the hotel API to retrieve
// additional data for an individual hotel. // additional data for an individual hotel.
included: z.array(RoomSchema).optional(), included: z.array(roomSchema).optional(),
}) })
const rate = z.object({ const rate = z.object({

View File

@@ -12,7 +12,7 @@ import {
getFiltersSchema, getFiltersSchema,
getHotelDataSchema, getHotelDataSchema,
getRatesSchema, getRatesSchema,
RoomSchema, roomSchema,
} from "./output" } from "./output"
import tempFilterData from "./tempFilterData.json" import tempFilterData from "./tempFilterData.json"
import tempRatesData from "./tempRatesData.json" import tempRatesData from "./tempRatesData.json"
@@ -63,7 +63,7 @@ export const hotelQueryRouter = router({
? included ? included
.filter((item) => item.type === "roomcategories") .filter((item) => item.type === "roomcategories")
.map((roomCategory) => { .map((roomCategory) => {
const validatedRoom = RoomSchema.safeParse(roomCategory) const validatedRoom = roomSchema.safeParse(roomCategory)
if (!validatedRoom.success) { if (!validatedRoom.success) {
console.error(`Get Room Category Data - Verified Data Error`) console.error(`Get Room Category Data - Verified Data Error`)
console.error(validatedRoom.error) console.error(validatedRoom.error)

View File

@@ -1,6 +1,6 @@
import { z } from "zod" import { z } from "zod"
import { getHotelDataSchema, RoomSchema } from "@/server/routers/hotels/output" import { getHotelDataSchema, roomSchema } from "@/server/routers/hotels/output"
export type HotelData = z.infer<typeof getHotelDataSchema> export type HotelData = z.infer<typeof getHotelDataSchema>
@@ -13,4 +13,4 @@ export type HotelTripAdvisor =
| NonNullable<HotelRatings>["tripAdvisor"] | NonNullable<HotelRatings>["tripAdvisor"]
| undefined | undefined
export type RoomData = z.infer<typeof RoomSchema> export type RoomData = z.infer<typeof roomSchema>