feat: Add Hotel endpoint and TRPC query
This commit is contained in:
@@ -11,6 +11,7 @@ export namespace endpoints {
|
|||||||
friendTransactions = "profile/v1/Transaction/friendTransactions",
|
friendTransactions = "profile/v1/Transaction/friendTransactions",
|
||||||
upcomingStays = "booking/v1/Stays/future",
|
upcomingStays = "booking/v1/Stays/future",
|
||||||
previousStays = "booking/v1/Stays/past",
|
previousStays = "booking/v1/Stays/past",
|
||||||
|
hotel = "hotel/v1/Hotels",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
/** Routers */
|
/** Routers */
|
||||||
import { contentstackRouter } from "./routers/contentstack"
|
import { contentstackRouter } from "./routers/contentstack"
|
||||||
|
import { hotelsRouter } from "./routers/hotels"
|
||||||
import { userRouter } from "./routers/user"
|
import { userRouter } from "./routers/user"
|
||||||
import { router } from "./trpc"
|
import { router } from "./trpc"
|
||||||
|
|
||||||
export const appRouter = router({
|
export const appRouter = router({
|
||||||
contentstack: contentstackRouter,
|
contentstack: contentstackRouter,
|
||||||
user: userRouter,
|
user: userRouter,
|
||||||
|
hotel: hotelsRouter,
|
||||||
})
|
})
|
||||||
|
|
||||||
export type AppRouter = typeof appRouter
|
export type AppRouter = typeof appRouter
|
||||||
|
|||||||
5
server/routers/hotels/index.ts
Normal file
5
server/routers/hotels/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { mergeRouters } from "@/server/trpc"
|
||||||
|
|
||||||
|
import { hotelQueryRouter } from "./query"
|
||||||
|
|
||||||
|
export const hotelsRouter = mergeRouters(hotelQueryRouter)
|
||||||
5
server/routers/hotels/input.ts
Normal file
5
server/routers/hotels/input.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { z } from "zod"
|
||||||
|
|
||||||
|
export const getHotelInputSchema = z.object({
|
||||||
|
hotelId: z.string(),
|
||||||
|
})
|
||||||
40
server/routers/hotels/query.ts
Normal file
40
server/routers/hotels/query.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
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
|
||||||
|
}),
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user