fix: align typings with loyalty-page branch
This commit is contained in:
@@ -4,9 +4,15 @@ import { badRequestError, internalServerError } from "@/server/errors/trpc"
|
||||
import { publicProcedure, router } from "@/server/trpc"
|
||||
|
||||
import { getAccountPageInput } from "./input"
|
||||
import { validateAccountPageSchema } from "./output"
|
||||
import { type AccountPage, validateAccountPageSchema } from "./output"
|
||||
|
||||
import type { GetAccountPageData } from "@/types/requests/myPages/accountpage"
|
||||
import { Embeds } from "@/types/requests/embeds"
|
||||
import {
|
||||
ContentEntries,
|
||||
GetAccountPageData,
|
||||
} from "@/types/requests/myPages/accountpage"
|
||||
import { Edges } from "@/types/requests/utils/edges"
|
||||
import { RTEDocument } from "@/types/rte/node"
|
||||
|
||||
export const accountPageQueryRouter = router({
|
||||
getOverview: publicProcedure
|
||||
@@ -30,8 +36,36 @@ export const accountPageQueryRouter = router({
|
||||
if (!validatedAccountPage.success) {
|
||||
throw badRequestError()
|
||||
}
|
||||
// TODO: Make returned data nicer
|
||||
const content =
|
||||
validatedAccountPage.data.all_account_page.items[0].content.map(
|
||||
(block) => {
|
||||
switch (block.__typename) {
|
||||
case ContentEntries.AccountPageContentDynamicContent:
|
||||
case ContentEntries.AccountPageContentShortcuts:
|
||||
return block
|
||||
case ContentEntries.AccountPageContentTextContent:
|
||||
return {
|
||||
...block,
|
||||
text_content: {
|
||||
content: {
|
||||
json: block.text_content.content.json as RTEDocument,
|
||||
embedded_itemsConnection: block.text_content.content
|
||||
.embedded_itemsConnection as Edges<Embeds>,
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return response.data.all_account_page.items[0]
|
||||
const accountPage = {
|
||||
...validatedAccountPage.data.all_account_page.items[0],
|
||||
content,
|
||||
} as AccountPage
|
||||
return accountPage
|
||||
} catch (error) {
|
||||
console.info(`Get Account Page Overview Error`)
|
||||
console.error(error)
|
||||
@@ -60,7 +94,35 @@ export const accountPageQueryRouter = router({
|
||||
throw badRequestError()
|
||||
}
|
||||
|
||||
return response.data.all_account_page.items[0]
|
||||
const content =
|
||||
validatedAccountPage.data.all_account_page.items[0].content.map(
|
||||
(block) => {
|
||||
switch (block.__typename) {
|
||||
case ContentEntries.AccountPageContentDynamicContent:
|
||||
case ContentEntries.AccountPageContentShortcuts:
|
||||
return block
|
||||
case ContentEntries.AccountPageContentTextContent:
|
||||
return {
|
||||
...block,
|
||||
text_content: {
|
||||
content: {
|
||||
json: block.text_content.content.json as RTEDocument,
|
||||
embedded_itemsConnection: block.text_content.content
|
||||
.embedded_itemsConnection as Edges<Embeds>,
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const accountPage = {
|
||||
...validatedAccountPage.data.all_account_page.items[0],
|
||||
content,
|
||||
} as AccountPage
|
||||
return accountPage
|
||||
} catch (error) {
|
||||
console.info(`Get Account Page Benefits Error`)
|
||||
console.error(error)
|
||||
|
||||
Reference in New Issue
Block a user