fix: refactor tracking requests

This commit is contained in:
Christel Westerberg
2024-07-15 13:35:00 +02:00
parent c7446032fe
commit 183e1cd6d2
14 changed files with 74 additions and 163 deletions

View File

@@ -125,6 +125,12 @@ export const validateAccountPageSchema = z.object({
url: z.string(),
title: z.string(),
content: z.array(accountPageContentItem),
system: z.object({
uid: z.string(),
locale: z.nativeEnum(Lang),
created_at: z.string(),
updated_at: z.string(),
}),
}),
})
@@ -189,18 +195,3 @@ export const validateAccountPageRefsSchema = z.object({
export type AccountPageRefsDataRaw = z.infer<
typeof validateAccountPageRefsSchema
>
//Tracking
const validateAccountTrackingData = z.object({
account_page: z.object({
system: z.object({
uid: z.string(),
locale: z.string(),
updated_at: z.string(),
created_at: z.string(),
}),
title: z.string().nullable(),
}),
})
export type AccountPageTackingData = z.infer<typeof validateAccountTrackingData>

View File

@@ -2,7 +2,6 @@ import { Lang } from "@/constants/languages"
import {
GetAccountPage,
GetAccountPageRefs,
GetTrackingAccountPage,
} from "@/lib/graphql/Query/AccountPage.graphql"
import { request } from "@/lib/graphql/request"
import { notFound } from "@/server/errors/trpc"
@@ -19,7 +18,6 @@ import {
type AccountPage,
AccountPageDataRaw,
AccountPageRefsDataRaw,
AccountPageTackingData,
validateAccountPageRefsSchema,
validateAccountPageSchema,
} from "./output"
@@ -136,32 +134,18 @@ export const accountPageQueryRouter = router({
content,
} as AccountPage
return accountPage
}),
tracking: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
const { lang, uid } = ctx
const response = await request<AccountPageTackingData>(
GetTrackingAccountPage,
{
locale: lang,
uid,
}
)
if (!response.data) {
throw notFound(response)
}
const accountTrackingData: TrackingSDKPageData = {
pageId: response.data.account_page.system.uid,
lang: response.data.account_page.system.locale as Lang,
publishedDate: response.data.account_page.system.updated_at,
createdDate: response.data.account_page.system.created_at,
const tracking: TrackingSDKPageData = {
pageId: validatedAccountPage.data.account_page.system.uid,
lang: validatedAccountPage.data.account_page.system.locale as Lang,
publishedDate: validatedAccountPage.data.account_page.system.updated_at,
createdDate: validatedAccountPage.data.account_page.system.created_at,
channel: TrackingChannelEnum["scandic-friends"],
pageType: `member${response.data.account_page.title}page`,
}
return accountTrackingData
return {
accountPage,
tracking,
}
}),
})