feat(SW-866): download invoice

This commit is contained in:
Simon Emanuelsson
2024-12-03 13:25:38 +01:00
parent 248dc4df19
commit 1d4a838860
26 changed files with 229 additions and 142 deletions

View File

@@ -8,6 +8,7 @@ import { router, serviceProcedure } from "@/server/trpc"
import { getHotelData } from "../hotels/query"
import { bookingConfirmationInput, getBookingStatusInput } from "./input"
import { bookingConfirmationSchema, createBookingSchema } from "./output"
import { getBookedHotelRoom } from "./utils"
const meter = metrics.getMeter("trpc.booking")
const getBookingConfirmationCounter = meter.createCounter(
@@ -144,6 +145,7 @@ export const bookingQueryRouter = router({
...hotelData.data.attributes,
included: hotelData.included,
},
room: getBookedHotelRoom(hotelData.included, booking.data.roomTypeCode),
}
}),
status: serviceProcedure.input(getBookingStatusInput).query(async function ({

View File

@@ -0,0 +1,27 @@
import { RoomData } from "@/types/hotel"
import { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation"
export function getBookedHotelRoom(
rooms: RoomData[] | undefined,
roomTypeCode: BookingConfirmation["booking"]["roomTypeCode"]
) {
if (!rooms?.length || !roomTypeCode) {
return null
}
const room = rooms?.find((r) => {
return r.roomTypes.find((roomType) => roomType.code === roomTypeCode)
})
if (!room) {
return null
}
const bedType = room.roomTypes.find(
(roomType) => roomType.code === roomTypeCode
)
if (!bedType) {
return null
}
return {
...room,
bedType,
}
}