71 lines
2.0 KiB
TypeScript
71 lines
2.0 KiB
TypeScript
import GetAccountPage from "@/lib/graphql/Query/AccountPage.graphql"
|
|
import { request } from "@/lib/graphql/request"
|
|
import { badRequestError, internalServerError } from "@/server/errors/trpc"
|
|
import { publicProcedure, router } from "@/server/trpc"
|
|
|
|
import { getAccountPageInput } from "./input"
|
|
import { validateAccountPageSchema } from "./output"
|
|
|
|
import type { GetAccountPageData } from "@/types/requests/myPages/accountpage"
|
|
|
|
export const accountPageQueryRouter = router({
|
|
getOverview: publicProcedure
|
|
.input(getAccountPageInput)
|
|
.query(async ({ input }) => {
|
|
try {
|
|
const url = "/my-pages/overview"
|
|
const response = await request<GetAccountPageData>(GetAccountPage, {
|
|
locale: input.lang,
|
|
url,
|
|
})
|
|
|
|
if (!response.data) {
|
|
throw badRequestError()
|
|
}
|
|
|
|
const validatedAccountPage = validateAccountPageSchema.safeParse(
|
|
response.data
|
|
)
|
|
|
|
if (!validatedAccountPage.success) {
|
|
throw badRequestError()
|
|
}
|
|
|
|
return response.data.all_account_page.items[0]
|
|
} catch (error) {
|
|
console.info(`Get Account Page Overview Error`)
|
|
console.error(error)
|
|
throw internalServerError()
|
|
}
|
|
}),
|
|
getBenefits: publicProcedure
|
|
.input(getAccountPageInput)
|
|
.query(async ({ input }) => {
|
|
try {
|
|
const url = "/my-pages/benefits"
|
|
const response = await request<GetAccountPageData>(GetAccountPage, {
|
|
locale: input.lang,
|
|
url,
|
|
})
|
|
|
|
if (!response.data) {
|
|
throw badRequestError()
|
|
}
|
|
|
|
const validatedAccountPage = validateAccountPageSchema.safeParse(
|
|
response.data
|
|
)
|
|
|
|
if (!validatedAccountPage.success) {
|
|
throw badRequestError()
|
|
}
|
|
|
|
return response.data.all_account_page.items[0]
|
|
} catch (error) {
|
|
console.info(`Get Account Page Benefits Error`)
|
|
console.error(error)
|
|
throw internalServerError()
|
|
}
|
|
}),
|
|
})
|