feat(WEB-127): add trpc to handle requests both serverside and clientside
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { badRequestError, internalServerError } from "@/server/errors"
|
||||
import { protectedProcedure, router } from "@/server/trpc"
|
||||
import { getUserSchema } from "./output"
|
||||
|
||||
export const userQueryRouter = router({
|
||||
get: protectedProcedure.query(async function (opts) {
|
||||
// TODO: Make request to get user data from Scandic API
|
||||
const response = await fetch(
|
||||
"https://jsonplaceholder.typicode.com/users/1",
|
||||
{
|
||||
cache: "no-store",
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
throw internalServerError()
|
||||
}
|
||||
const json = await response.json()
|
||||
const validJson = getUserSchema.parse(json)
|
||||
if (!validJson) {
|
||||
throw badRequestError()
|
||||
}
|
||||
return validJson
|
||||
}),
|
||||
})
|
||||
Reference in New Issue
Block a user