refactor: zod validation and pr comments
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
ContactConfig,
|
||||
ContactFieldGroups,
|
||||
} from "@/types/requests/contactConfig"
|
||||
} from "@/server/routers/contentstack/contactConfig/output"
|
||||
|
||||
export function getValueFromContactConfig(
|
||||
keyString: string,
|
||||
@@ -16,4 +16,5 @@ export function getValueFromContactConfig(
|
||||
|
||||
return fieldGroup[key]
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { DocumentNode } from "graphql"
|
||||
import { DocumentNode, print } from "graphql"
|
||||
|
||||
import { Lang } from "@/constants/languages"
|
||||
import { env } from "@/env/server"
|
||||
import GetContentTypeUid from "@/lib/graphql/Query/ContentTypeUid.graphql"
|
||||
import { GetContentTypeUid } from "@/lib/graphql/Query/ContentTypeUid.graphql"
|
||||
|
||||
import type { GetContentTypeUidType } from "@/types/requests/contentTypeUid"
|
||||
import { validateContentTypeUid } from "@/types/requests/contentTypeUid"
|
||||
|
||||
export enum PageTypeEnum {
|
||||
CurrentBlocksPage = "CurrentBlocksPage",
|
||||
@@ -16,7 +16,6 @@ export async function getContentTypeByPathName(
|
||||
pathNameWithoutLang: string,
|
||||
lang = Lang.en
|
||||
) {
|
||||
const print = (await import("graphql/language/printer")).print
|
||||
const result = await fetch(env.CMS_URL, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@@ -33,7 +32,17 @@ export async function getContentTypeByPathName(
|
||||
})
|
||||
|
||||
const pageTypeData = await result.json()
|
||||
const pageType = pageTypeData.data as GetContentTypeUidType
|
||||
|
||||
const validatedContentTypeUid = validateContentTypeUid.safeParse(
|
||||
pageTypeData.data
|
||||
)
|
||||
|
||||
if (!validatedContentTypeUid.success) {
|
||||
console.error(validatedContentTypeUid.error)
|
||||
return null
|
||||
}
|
||||
|
||||
const pageType = validatedContentTypeUid.data
|
||||
|
||||
if (pageType.all_content_page.total) {
|
||||
return PageTypeEnum.ContentPage
|
||||
|
||||
Reference in New Issue
Block a user