fix: clean up hotel and its typings

This commit is contained in:
Simon Emanuelsson
2024-12-17 16:17:25 +01:00
parent ec74af8814
commit 13a164242f
110 changed files with 1931 additions and 1559 deletions

View File

@@ -5,7 +5,7 @@ import { dt } from "@/lib/dt"
import { badRequestError, serverErrorByStatus } from "@/server/errors/trpc"
import { router, serviceProcedure } from "@/server/trpc"
import { getHotelData } from "../hotels/query"
import { getHotel } from "../hotels/query"
import { bookingConfirmationInput, getBookingStatusInput } from "./input"
import { bookingConfirmationSchema, createBookingSchema } from "./output"
import { getBookedHotelRoom } from "./utils"
@@ -84,8 +84,12 @@ export const bookingQueryRouter = router({
throw badRequestError()
}
const hotelData = await getHotelData(
{ hotelId: booking.data.hotelId, language: ctx.lang },
const hotelData = await getHotel(
{
hotelId: booking.data.hotelId,
isCardOnlyPayment: false,
language: ctx.lang,
},
ctx.serviceToken
)
@@ -123,14 +127,12 @@ export const bookingQueryRouter = router({
* Add hotels check in and out times to booking check in and out date
* as that is date only (YYYY-MM-DD)
*/
const checkInTime =
hotelData.data.attributes.hotelFacts.checkin.checkInTime
const checkInTime = hotelData.hotel.hotelFacts.checkin.checkInTime
const [checkInHour, checkInMinute] = checkInTime.split(":")
const checkIn = dt(booking.data.checkInDate)
.set("hour", Number(checkInHour))
.set("minute", Number(checkInMinute))
const checkOutTime =
hotelData.data.attributes.hotelFacts.checkin.checkOutTime
const checkOutTime = hotelData.hotel.hotelFacts.checkin.checkOutTime
const [checkOutHour, checkOutMinute] = checkOutTime.split(":")
const checkOut = dt(booking.data.checkOutDate)
.set("hour", Number(checkOutHour))
@@ -140,13 +142,10 @@ export const bookingQueryRouter = router({
booking.data.checkOutDate = checkOut.toDate()
return {
...hotelData,
booking: booking.data,
hotel: {
...hotelData.data.attributes,
included: hotelData.included,
},
room: getBookedHotelRoom(
hotelData.included.rooms,
hotelData.roomCategories,
booking.data.roomTypeCode
),
}

View File

@@ -1,8 +1,8 @@
import type { RoomData } from "@/types/hotel"
import type { Room } from "@/types/hotel"
import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
export function getBookedHotelRoom(
rooms: RoomData[] | undefined,
rooms: Room[] | undefined,
roomTypeCode: BookingConfirmation["booking"]["roomTypeCode"]
) {
if (!rooms?.length || !roomTypeCode) {