fix(SW-285): fix validation
This commit is contained in:
@@ -9,6 +9,7 @@ import { makeImageVaultImage } from "@/utils/imageVault"
|
|||||||
|
|
||||||
import { validateContentPageSchema } from "./output"
|
import { validateContentPageSchema } from "./output"
|
||||||
|
|
||||||
|
import { ImageVaultAsset } from "@/types/components/imageVault"
|
||||||
import {
|
import {
|
||||||
TrackingChannelEnum,
|
TrackingChannelEnum,
|
||||||
TrackingSDKPageData,
|
TrackingSDKPageData,
|
||||||
@@ -27,45 +28,45 @@ export const contentPageQueryRouter = router({
|
|||||||
|
|
||||||
const response = await request<ContentPageDataRaw>(
|
const response = await request<ContentPageDataRaw>(
|
||||||
GetContentPage,
|
GetContentPage,
|
||||||
{
|
{ locale: lang, uid },
|
||||||
locale: lang,
|
{ cache: "force-cache", next: { tags: [generateTag(lang, uid)] } }
|
||||||
uid,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
cache: "force-cache",
|
|
||||||
next: {
|
|
||||||
tags: [generateTag(lang, uid)],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!response.data) {
|
const { content_page } = response.data
|
||||||
|
if (!content_page) {
|
||||||
throw notFound(response)
|
throw notFound(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
const validatedContentPage = validateContentPageSchema.safeParse(
|
const validatedContentPage = validateContentPageSchema.safeParse({
|
||||||
response.data
|
content_page: {
|
||||||
)
|
...content_page,
|
||||||
|
hero_image: makeImageVaultImage(content_page.hero_image),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
if (!validatedContentPage.success) {
|
if (!validatedContentPage.success) {
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to validate Contentpage Data - (lang: ${lang}, uid: ${uid})`
|
`Failed to validate Contentpage Data - (lang: ${lang}, uid: ${uid})`
|
||||||
)
|
)
|
||||||
console.error(validatedContentPage.error)
|
console.error(validatedContentPage.error?.format())
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
const contentPageData = validatedContentPage.data.content_page
|
// Destructure hero_image and rename it to heroImage
|
||||||
|
const { hero_image: heroImage, ...restContentPage } =
|
||||||
|
validatedContentPage.data.content_page
|
||||||
|
|
||||||
|
// Construct the contentPage object with the correct structure
|
||||||
const contentPage: ContentPage = {
|
const contentPage: ContentPage = {
|
||||||
...contentPageData,
|
...restContentPage,
|
||||||
heroImage: makeImageVaultImage(contentPageData.hero_image),
|
heroImage: heroImage as ImageVaultAsset | undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
const tracking: TrackingSDKPageData = {
|
const tracking: TrackingSDKPageData = {
|
||||||
pageId: contentPageData.system.uid,
|
pageId: contentPage.system.uid,
|
||||||
lang: contentPageData.system.locale as Lang,
|
lang: contentPage.system.locale as Lang,
|
||||||
publishedDate: contentPageData.system.updated_at,
|
publishedDate: contentPage.system.updated_at,
|
||||||
createdDate: contentPageData.system.created_at,
|
createdDate: contentPage.system.created_at,
|
||||||
channel: TrackingChannelEnum["static-content-page"],
|
channel: TrackingChannelEnum["static-content-page"],
|
||||||
pageType: "staticcontentpage",
|
pageType: "staticcontentpage",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user