fix: refactor tracking requests
This commit is contained in:
@@ -2,7 +2,6 @@ import { Lang } from "@/constants/languages"
|
||||
import {
|
||||
GetLoyaltyPage,
|
||||
GetLoyaltyPageRefs,
|
||||
GetTrackingLoyaltyPage,
|
||||
} from "@/lib/graphql/Query/LoyaltyPage.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { notFound } from "@/server/errors/trpc"
|
||||
@@ -20,7 +19,6 @@ import { removeEmptyObjects } from "../../utils"
|
||||
import {
|
||||
LoyaltyPage,
|
||||
type LoyaltyPageRefsDataRaw,
|
||||
LoyaltyPageTackingData,
|
||||
validateLoyaltyPageRefsSchema,
|
||||
validateLoyaltyPageSchema,
|
||||
} from "./output"
|
||||
@@ -228,24 +226,6 @@ export const loyaltyPageQueryRouter = router({
|
||||
return null
|
||||
}
|
||||
|
||||
// Assert LoyaltyPage type to get correct typings for RTE fields
|
||||
return validatedLoyaltyPage.data as LoyaltyPage
|
||||
}),
|
||||
tracking: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
const response = await request<LoyaltyPageTackingData>(
|
||||
GetTrackingLoyaltyPage,
|
||||
{
|
||||
locale: lang,
|
||||
uid,
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
const loyaltyTrackingData: TrackingSDKPageData = {
|
||||
pageId: response.data.loyalty_page.system.uid,
|
||||
lang: response.data.loyalty_page.system.locale as Lang,
|
||||
@@ -255,6 +235,10 @@ export const loyaltyPageQueryRouter = router({
|
||||
pageType: "loyaltycontentpage",
|
||||
}
|
||||
|
||||
return loyaltyTrackingData
|
||||
// Assert LoyaltyPage type to get correct typings for RTE fields
|
||||
return {
|
||||
loyaltyPage: validatedLoyaltyPage.data as LoyaltyPage,
|
||||
tracking: loyaltyTrackingData,
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user