41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import * as api from "@/lib/api"
|
|
import { protectedProcedure, publicProcedure, router } from "@/server/trpc"
|
|
|
|
import { getHotelInputSchema } from "./input"
|
|
|
|
export const hotelQueryRouter = router({
|
|
// TODO: Should be public.
|
|
getHotel: protectedProcedure
|
|
.input(getHotelInputSchema)
|
|
.query(async ({ input, ctx }) => {
|
|
const { hotelId } = input
|
|
|
|
const params = new URLSearchParams()
|
|
params.set("hotelId", hotelId.toString())
|
|
console.log("hotel fetch start")
|
|
const apiResponse = await api.get(
|
|
api.endpoints.v1.hotel,
|
|
{
|
|
cache: "no-store",
|
|
headers: {
|
|
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
|
},
|
|
},
|
|
params
|
|
)
|
|
console.log("apiResponse", apiResponse)
|
|
|
|
if (!apiResponse.ok) {
|
|
console.info(`API Response Failed - Getting Hotel`)
|
|
console.error(apiResponse)
|
|
return null
|
|
}
|
|
|
|
const apiJson = await apiResponse.json()
|
|
console.log("apiJson", apiJson)
|
|
// return null
|
|
// TODO: validate apiJson.
|
|
return apiJson
|
|
}),
|
|
})
|