From 3a2a58a9ca1e83ab688c2c11b668aaaf7c329eaf Mon Sep 17 00:00:00 2001 From: Chuma McPhoy Date: Wed, 14 Aug 2024 08:27:56 +0200 Subject: [PATCH] fix(SW-188): improve semantics, use hotel instead of attribute naming --- .../hotelreservation/select-hotel/page.tsx | 4 ++-- .../(public)/hotelreservation/select-rate/page.tsx | 9 ++++----- components/ContentType/HotelPage/HotelPage.tsx | 14 +++++++------- server/routers/hotels/output.ts | 2 +- server/routers/hotels/query.ts | 2 +- server/utils.ts | 9 +++++++++ utils/languages.ts | 9 --------- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx index ca65e8a21..16815db38 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx @@ -27,8 +27,8 @@ export default async function SelectHotelPage({ return null } - const { attributes } = hotelData - const hotels = [attributes] + const { hotel } = hotelData + const hotels = [hotel] const hotelFilters = await serverClient().hotel.getFilters({ hotelId: "879", diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-rate/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-rate/page.tsx index f0d8c8be3..f98ad11e3 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-rate/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-rate/page.tsx @@ -15,14 +15,13 @@ export default async function SelectRate({ params }: PageArgs) { setLang(params.lang) // TODO: pass the correct hotel ID - const hotel = await serverClient().hotel.getHotel({ + const hotelData = await serverClient().hotel.getHotel({ hotelId: "879", language: getLang(), }) - if (!hotel) return null - - const { attributes } = hotel + if (!hotelData) return null + const { hotel } = hotelData const rooms = await serverClient().hotel.getRates({ // TODO: pass the correct hotel ID and all other parameters that should be included in the search @@ -33,7 +32,7 @@ export default async function SelectRate({ params }: PageArgs) {
- +
diff --git a/components/ContentType/HotelPage/HotelPage.tsx b/components/ContentType/HotelPage/HotelPage.tsx index efc300eca..88ca4a487 100644 --- a/components/ContentType/HotelPage/HotelPage.tsx +++ b/components/ContentType/HotelPage/HotelPage.tsx @@ -25,7 +25,7 @@ export default async function HotelPage() { include: ["RoomCategories"], }) if (!hotelData) return null - const { attributes, roomCategories } = hotelData + const { hotel, roomCategories } = hotelData return (
@@ -33,14 +33,14 @@ export default async function HotelPage() {
- +
diff --git a/server/routers/hotels/output.ts b/server/routers/hotels/output.ts index 0a87f935b..6bf03b754 100644 --- a/server/routers/hotels/output.ts +++ b/server/routers/hotels/output.ts @@ -1,6 +1,6 @@ import { z } from "zod" -import { fromUppercaseToLangEnum } from "@/utils/languages" +import { fromUppercaseToLangEnum } from "@/server/utils" const RatingsSchema = z .object({ diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index b8353df28..aa23e91c5 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -72,7 +72,7 @@ export const hotelQueryRouter = router({ }) return { - attributes: validatedHotelData.data.data.attributes, + hotel: validatedHotelData.data.data.attributes, roomCategories: roomCategories, } }), diff --git a/server/utils.ts b/server/utils.ts index 3ea37bf6b..ee0409ee4 100644 --- a/server/utils.ts +++ b/server/utils.ts @@ -26,3 +26,12 @@ const toApiLangMap: { [key in Lang]: string } = { [Lang.da]: "Da", [Lang.de]: "De", } + +/** + * Helper function to convert langs in uppercase or capitalized format (e.g. the Hotel endpoint) + * to to Lang enum. + */ +export function fromUppercaseToLangEnum(lang: string): Lang | undefined { + const lowerCaseLang = lang.toLowerCase() + return Object.values(Lang).find((l) => l === lowerCaseLang) +} diff --git a/utils/languages.ts b/utils/languages.ts index bace608b3..897ae1b07 100644 --- a/utils/languages.ts +++ b/utils/languages.ts @@ -5,12 +5,3 @@ export function findLang(pathname: string) { (l) => pathname.startsWith(`/${l}/`) || pathname === `/${l}` ) } - -/** - * Helper function to convert langs in uppercase or capitalized format (e.g. the Hotel endpoint) - * to to Lang enum. - */ -export function fromUppercaseToLangEnum(lang: string): Lang | undefined { - const lowerCaseLang = lang.toLowerCase() - return Object.values(Lang).find((l) => l === lowerCaseLang) -}