feat(SW-266): Replacing static metadata with data from Contentstack on Loyalty pages and Account Pages
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { internalServerError, notFound } from "@/server/errors/trpc"
|
||||
|
||||
import { getMetaDataSchema, Page } from "./output"
|
||||
|
||||
export type Variables = {
|
||||
locale: Lang
|
||||
url: string
|
||||
}
|
||||
|
||||
export async function getResponse<T>(query: string, variables: Variables) {
|
||||
const response = await request<T>(query, variables)
|
||||
if (!response.data) {
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
export function getMetaData(page: Page) {
|
||||
const pageMetaData = {
|
||||
title: page.web.seo_metadata.title,
|
||||
description: page.web.seo_metadata.description,
|
||||
imageConnection: page.web.seo_metadata.imageConnection,
|
||||
uid: page.system.uid,
|
||||
}
|
||||
const validatedMetaData = getMetaDataSchema.safeParse(pageMetaData)
|
||||
if (!validatedMetaData.success) {
|
||||
throw internalServerError(validatedMetaData.error)
|
||||
}
|
||||
|
||||
return validatedMetaData.data
|
||||
}
|
||||
Reference in New Issue
Block a user