fix: structure logged data
This commit is contained in:
@@ -35,7 +35,10 @@ import { RTEDocument } from "@/types/rte/node"
|
||||
export const accountPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
|
||||
console.info(
|
||||
"contentstack.accountPage.refs start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
const refsResponse = await request<AccountPageRefsDataRaw>(
|
||||
GetAccountPageRefs,
|
||||
{
|
||||
@@ -48,6 +51,10 @@ export const accountPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
console.error(
|
||||
"contentstack.accountPage.refs not found error",
|
||||
JSON.stringify({ query: { lang, uid }, error: refsResponse })
|
||||
)
|
||||
throw notFound(refsResponse)
|
||||
}
|
||||
|
||||
@@ -56,8 +63,13 @@ export const accountPageQueryRouter = router({
|
||||
const validatedAccountPageRefs =
|
||||
validateAccountPageRefsSchema.safeParse(cleanedData)
|
||||
if (!validatedAccountPageRefs.success) {
|
||||
console.error(`Failed to validate My Page Refs - (uid: ${uid})`)
|
||||
console.error(validatedAccountPageRefs.error)
|
||||
console.error(
|
||||
"contentstack.accountPage.refs validation error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedAccountPageRefs.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -67,7 +79,10 @@ export const accountPageQueryRouter = router({
|
||||
generateTags(lang, connections),
|
||||
generateTag(lang, validatedAccountPageRefs.data.account_page.system.uid),
|
||||
].flat()
|
||||
console.info("contentstack.accountPage start ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.accountPage start",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
const response = await request<AccountPageDataRaw>(
|
||||
GetAccountPage,
|
||||
{
|
||||
@@ -78,7 +93,13 @@ export const accountPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error("contentstack.accountPage not found error", { lang, uid })
|
||||
console.error(
|
||||
"contentstack.accountPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -89,11 +110,17 @@ export const accountPageQueryRouter = router({
|
||||
if (!validatedAccountPage.success) {
|
||||
console.error(
|
||||
"contentstack.accountPage validation error",
|
||||
JSON.stringify(validatedAccountPage.error)
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedAccountPage.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.accountPage success ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.accountPage success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
// TODO: Make returned data nicer
|
||||
const content = validatedAccountPage.data.account_page.content.map(
|
||||
(block) => {
|
||||
|
||||
@@ -33,16 +33,18 @@ import {
|
||||
export const baseQueryRouter = router({
|
||||
contact: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
const { lang } = ctx
|
||||
console.info("contentstack.config start ", JSON.stringify({ lang }))
|
||||
console.info(
|
||||
"contentstack.config start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const response = await request<ContactConfigData>(GetContactConfig, {
|
||||
locale: lang,
|
||||
})
|
||||
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.config not found error ",
|
||||
JSON.stringify({ lang }),
|
||||
JSON.stringify(response)
|
||||
"contentstack.config not found error",
|
||||
JSON.stringify({ query: { lang }, error: response })
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -53,29 +55,34 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!validatedContactConfigConfig.success) {
|
||||
console.error(
|
||||
"contentstack.config validation error ",
|
||||
JSON.stringify({ lang }),
|
||||
JSON.stringify(validatedContactConfigConfig.error)
|
||||
"contentstack.config validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedContactConfigConfig.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.config success ", JSON.stringify({ lang }))
|
||||
console.info(
|
||||
"contentstack.config success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
return validatedContactConfigConfig.data.all_contact_config.items[0]
|
||||
}),
|
||||
header: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
.query(async ({ input }) => {
|
||||
console.info(
|
||||
"contentstack.header.ref start ",
|
||||
JSON.stringify({ lang: input.lang })
|
||||
"contentstack.header.ref start",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
)
|
||||
const responseRef = await request<HeaderRefDataRaw>(GetCurrentHeaderRef, {
|
||||
locale: input.lang,
|
||||
})
|
||||
console.info(
|
||||
"contentstack.header. start ",
|
||||
"contentstack.header start",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
query: { lang: input.lang },
|
||||
})
|
||||
)
|
||||
|
||||
@@ -95,11 +102,13 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.header not found error ",
|
||||
"contentstack.header not found error",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
}),
|
||||
JSON.stringify(response)
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -112,16 +121,18 @@ export const baseQueryRouter = router({
|
||||
console.error(
|
||||
"contentstack.header validation error",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
}),
|
||||
JSON.stringify(validatedHeaderConfig.error)
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
error: validatedHeaderConfig.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info(
|
||||
"contentstack.header success ",
|
||||
"contentstack.header success",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
query: { lang: input.lang },
|
||||
})
|
||||
)
|
||||
const logo =
|
||||
@@ -136,15 +147,20 @@ export const baseQueryRouter = router({
|
||||
footer: contentstackBaseProcedure
|
||||
.input(langInput)
|
||||
.query(async ({ input }) => {
|
||||
console.info("contentstack.footer.ref start ", { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.footer.ref start",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
)
|
||||
const responseRef = await request<FooterRefDataRaw>(GetCurrentFooterRef, {
|
||||
locale: input.lang,
|
||||
})
|
||||
// There's currently no error handling/validation for the responseRef, should it be added?
|
||||
console.info(
|
||||
"contentstack.footer start ",
|
||||
"contentstack.footer start",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
})
|
||||
)
|
||||
const response = await request<FooterDataRaw>(
|
||||
@@ -164,11 +180,13 @@ export const baseQueryRouter = router({
|
||||
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.footer not found error ",
|
||||
"contentstack.footer not found error",
|
||||
JSON.stringify({
|
||||
lang: input.lang,
|
||||
}),
|
||||
JSON.stringify(response)
|
||||
query: {
|
||||
lang: input.lang,
|
||||
},
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -180,12 +198,17 @@ export const baseQueryRouter = router({
|
||||
if (!validatedFooterConfig.success) {
|
||||
console.error(
|
||||
"contentstack.footer validation error",
|
||||
JSON.stringify({ lang: input.lang }),
|
||||
JSON.stringify(validatedFooterConfig.error)
|
||||
JSON.stringify({
|
||||
query: { lang: input.lang },
|
||||
error: validatedFooterConfig.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.footer success ", { lang: input.lang })
|
||||
console.info(
|
||||
"contentstack.footer success",
|
||||
JSON.stringify({ query: { lang: input.lang } })
|
||||
)
|
||||
return validatedFooterConfig.data.all_current_footer.items[0]
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -8,7 +8,12 @@ import { HotelPage, HotelPageDataRaw, validateHotelPageSchema } from "./output"
|
||||
export const hotelPageQueryRouter = router({
|
||||
get: contentstackBaseProcedure.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
console.info("contentstack.hotelPage start ", JSON.stringify({ lang, uid }))
|
||||
console.info(
|
||||
"contentstack.hotelPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const response = await request<HotelPageDataRaw>(GetHotelPage, {
|
||||
locale: lang,
|
||||
uid,
|
||||
@@ -16,7 +21,10 @@ export const hotelPageQueryRouter = router({
|
||||
if (!response.data) {
|
||||
console.error(
|
||||
"contentstack.hotelPage not found error",
|
||||
JSON.stringify({ lang, uid })
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -26,8 +34,10 @@ export const hotelPageQueryRouter = router({
|
||||
if (!validatedHotelPage.success) {
|
||||
console.error(
|
||||
"contentstack.hotelPage validation error",
|
||||
JSON.stringify({ lang, uid }),
|
||||
JSON.stringify(validatedHotelPage.error)
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedHotelPage.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -35,7 +45,12 @@ export const hotelPageQueryRouter = router({
|
||||
const hotelPage = {
|
||||
...validatedHotelPage.data.hotel_page,
|
||||
} as HotelPage
|
||||
|
||||
console.info(
|
||||
"contentstack.hotelPage success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
return hotelPage
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -132,11 +132,13 @@ export const languageSwitcherQueryRouter = router({
|
||||
return { lang: ctx.lang, urls: baseUrls }
|
||||
}
|
||||
console.info(
|
||||
"contentstack.languageSwitcher start ",
|
||||
"contentstack.languageSwitcher start",
|
||||
JSON.stringify({
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
query: {
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
},
|
||||
})
|
||||
)
|
||||
const res = await getLanguageSwitcher({
|
||||
@@ -164,11 +166,27 @@ export const languageSwitcherQueryRouter = router({
|
||||
if (!validatedLanguageSwitcherData.success) {
|
||||
console.error(
|
||||
"contentstack.languageSwitcher validation error",
|
||||
JSON.stringify(validatedLanguageSwitcherData.error)
|
||||
JSON.stringify({
|
||||
query: {
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
},
|
||||
error: validatedLanguageSwitcherData.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.languageSwitcher success")
|
||||
console.info(
|
||||
"contentstack.languageSwitcher success",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
uid: ctx.uid,
|
||||
lang: ctx.lang,
|
||||
contentType: ctx.contentType,
|
||||
},
|
||||
})
|
||||
)
|
||||
return {
|
||||
lang: ctx.lang,
|
||||
urls,
|
||||
|
||||
@@ -37,7 +37,12 @@ import {
|
||||
export const loyaltyPageQueryRouter = router({
|
||||
get: contentstackExtendedProcedureUID.query(async ({ ctx }) => {
|
||||
const { lang, uid } = ctx
|
||||
console.info("contentstack.loyaltyPage.refs start ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage.refs start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const refsResponse = await request<LoyaltyPageRefsDataRaw>(
|
||||
GetLoyaltyPageRefs,
|
||||
{
|
||||
@@ -50,10 +55,16 @@ export const loyaltyPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
console.error("contentstack.loyaltyPage.refs not found error", {
|
||||
lang,
|
||||
uid,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.loyaltyPage.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
uid,
|
||||
},
|
||||
error: JSON.stringify(refsResponse),
|
||||
})
|
||||
)
|
||||
throw notFound(refsResponse)
|
||||
}
|
||||
|
||||
@@ -64,19 +75,31 @@ export const loyaltyPageQueryRouter = router({
|
||||
if (!validatedLoyaltyPageRefs.success) {
|
||||
console.error(
|
||||
"contentstack.loyaltyPage.refs validation error",
|
||||
{ lang, uid },
|
||||
JSON.stringify(validatedLoyaltyPageRefs.error)
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedLoyaltyPageRefs.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.loyaltyPage.refs success ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage.refs success",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const connections = getConnections(validatedLoyaltyPageRefs.data)
|
||||
|
||||
const tags = [
|
||||
generateTags(lang, connections),
|
||||
generateTag(lang, validatedLoyaltyPageRefs.data.loyalty_page.system.uid),
|
||||
].flat()
|
||||
console.info("contentstack.loyaltyPage start ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage start",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
})
|
||||
)
|
||||
const response = await request<any>(
|
||||
GetLoyaltyPage,
|
||||
{
|
||||
@@ -87,7 +110,13 @@ export const loyaltyPageQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error("contentstack.loyaltyPage not found error", { lang, uid })
|
||||
console.error(
|
||||
"contentstack.loyaltyPage not found error",
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: response,
|
||||
})
|
||||
)
|
||||
throw notFound(response)
|
||||
}
|
||||
|
||||
@@ -198,8 +227,10 @@ export const loyaltyPageQueryRouter = router({
|
||||
if (!validatedLoyaltyPage.success) {
|
||||
console.error(
|
||||
"contentstack.loyaltyPage validation error",
|
||||
{ lang, uid },
|
||||
JSON.stringify(validatedLoyaltyPage.error)
|
||||
JSON.stringify({
|
||||
query: { lang, uid },
|
||||
error: validatedLoyaltyPage.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -212,7 +243,10 @@ export const loyaltyPageQueryRouter = router({
|
||||
channel: TrackingChannelEnum["scandic-friends"],
|
||||
pageType: "loyaltycontentpage",
|
||||
}
|
||||
console.info("contentstack.loyaltyPage success ", { lang, uid })
|
||||
console.info(
|
||||
"contentstack.loyaltyPage success",
|
||||
JSON.stringify({ query: { lang, uid } })
|
||||
)
|
||||
// Assert LoyaltyPage type to get correct typings for RTE fields
|
||||
return {
|
||||
loyaltyPage,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { error } from "console"
|
||||
|
||||
import {
|
||||
GetNavigationMyPages,
|
||||
GetNavigationMyPagesRefs,
|
||||
@@ -61,7 +63,10 @@ export function mapMenuItems(menuItems: MenuItems) {
|
||||
export const navigationQueryRouter = router({
|
||||
get: contentstackBaseProcedure.query(async function ({ ctx }) {
|
||||
const { lang } = ctx
|
||||
console.info("contentstack.myPages.navigation.ref start ", { lang })
|
||||
console.info(
|
||||
"contentstack.myPages.navigation.refs start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const refsResponse = await request<GetNavigationMyPagesRefsData>(
|
||||
GetNavigationMyPagesRefs,
|
||||
{ locale: lang },
|
||||
@@ -71,21 +76,36 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!refsResponse.data) {
|
||||
console.error("contentstack.myPages.navigation.ref not found error ", {
|
||||
lang,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.myPages.navigation.refs not found error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: refsResponse,
|
||||
})
|
||||
)
|
||||
throw notFound(refsResponse)
|
||||
}
|
||||
|
||||
const validatedMyPagesNavigationRefs =
|
||||
navigationRefsPayloadSchema.safeParse(refsResponse.data)
|
||||
if (!validatedMyPagesNavigationRefs.success) {
|
||||
console.error("contentstack.myPages.navigation.ref validation error ", {
|
||||
lang,
|
||||
})
|
||||
console.error(
|
||||
"contentstack.myPages.navigation.refs validation error",
|
||||
JSON.stringify({
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: validatedMyPagesNavigationRefs.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("contentstack.myPages.navigation.ref success ", { lang })
|
||||
console.info(
|
||||
"contentstack.myPages.navigation.refs success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const connections = getConnections(validatedMyPagesNavigationRefs.data)
|
||||
|
||||
const tags = [
|
||||
@@ -96,7 +116,10 @@ export const navigationQueryRouter = router({
|
||||
.system.uid
|
||||
),
|
||||
].flat()
|
||||
console.info("contentstack.myPages.navigation start ", { lang })
|
||||
console.info(
|
||||
"contentstack.myPages.navigation start",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
const response = await request<GetNavigationMyPagesData>(
|
||||
GetNavigationMyPages,
|
||||
{ locale: lang },
|
||||
@@ -104,8 +127,11 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!response.data) {
|
||||
console.error("contentstack.myPages.navigation not found error ", {
|
||||
lang,
|
||||
console.error("contentstack.myPages.navigation not found error", {
|
||||
query: {
|
||||
lang,
|
||||
},
|
||||
error: response,
|
||||
})
|
||||
throw notFound(response)
|
||||
}
|
||||
@@ -115,9 +141,11 @@ export const navigationQueryRouter = router({
|
||||
)
|
||||
if (!validatedMyPagesNavigation.success) {
|
||||
console.error(
|
||||
"contentstack.myPages.navigation validation error ",
|
||||
JSON.stringify({ lang }),
|
||||
JSON.stringify(validatedMyPagesNavigation.error)
|
||||
"contentstack.myPages.navigation.payload validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedMyPagesNavigation.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -133,12 +161,20 @@ export const navigationQueryRouter = router({
|
||||
const validatedNav = getNavigationSchema.safeParse(nav)
|
||||
if (!validatedNav.success) {
|
||||
console.error(
|
||||
`Failed to validate My Pages Navigation Return Data - (lang: ${lang}`
|
||||
"contentstack.myPages.navigation validation error",
|
||||
JSON.stringify({
|
||||
query: { lang },
|
||||
error: validatedNav.error,
|
||||
})
|
||||
)
|
||||
|
||||
console.error(validatedNav.error)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info(
|
||||
"contentstack.myPages.navigation success",
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
return validatedNav.data
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -32,7 +32,12 @@ export const hotelQueryRouter = router({
|
||||
params.include = include.join(",")
|
||||
}
|
||||
|
||||
console.info("api.hotels.hotel start")
|
||||
console.info(
|
||||
"api.hotels.hotel start",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
})
|
||||
)
|
||||
const apiResponse = await api.get(
|
||||
`${api.endpoints.v1.hotels}/${hotelId}`,
|
||||
{
|
||||
@@ -45,7 +50,13 @@ export const hotelQueryRouter = router({
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
console.error("api.hotels.hotel error, ", JSON.stringify(apiResponse))
|
||||
console.error(
|
||||
"api.hotels.hotel error",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
error: apiResponse,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
const apiJson = await apiResponse.json()
|
||||
@@ -53,8 +64,11 @@ export const hotelQueryRouter = router({
|
||||
|
||||
if (!validatedHotelData.success) {
|
||||
console.error(
|
||||
"api.hotels.hotel validation error ",
|
||||
JSON.stringify(validatedHotelData.error)
|
||||
"api.hotels.hotel validation error",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
error: validatedHotelData.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
@@ -63,18 +77,28 @@ export const hotelQueryRouter = router({
|
||||
|
||||
const roomCategories = included
|
||||
? included
|
||||
.filter((item) => item.type === "roomcategories")
|
||||
.map((roomCategory) => {
|
||||
const validatedRoom = roomSchema.safeParse(roomCategory)
|
||||
if (!validatedRoom.success) {
|
||||
console.error(`Get Room Category Data - Verified Data Error`)
|
||||
console.error(validatedRoom.error)
|
||||
throw badRequestError()
|
||||
}
|
||||
return validatedRoom.data
|
||||
})
|
||||
.filter((item) => item.type === "roomcategories")
|
||||
.map((roomCategory) => {
|
||||
const validatedRoom = roomSchema.safeParse(roomCategory)
|
||||
if (!validatedRoom.success) {
|
||||
console.error(
|
||||
"api.hotels.hotel validation error",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
error: validatedRoom.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
return validatedRoom.data
|
||||
})
|
||||
: []
|
||||
console.info("api.hotels.hotel success")
|
||||
console.info(
|
||||
"api.hotels.hotel success",
|
||||
JSON.stringify({
|
||||
query: { hotelId, params: params.toString() },
|
||||
})
|
||||
)
|
||||
return {
|
||||
hotel: validatedHotelData.data.data.attributes,
|
||||
roomCategories: roomCategories,
|
||||
@@ -90,31 +114,36 @@ export const hotelQueryRouter = router({
|
||||
// const apiLang = toApiLang(language)
|
||||
// params.set("hotelId", hotelId.toString())
|
||||
// params.set("language", apiLang)
|
||||
console.info("api.hotels.rates start")
|
||||
console.info("api.hotels.rates start", JSON.stringify({}))
|
||||
const validatedHotelData = getRatesSchema.safeParse(tempRatesData)
|
||||
|
||||
if (!tempRatesData) {
|
||||
console.error("api.hotels.rates error, ", {})
|
||||
console.error("api.hotels.rates error", JSON.stringify({ error: null }))
|
||||
//Can't return null here since consuming component does not handle null yet
|
||||
// return null
|
||||
}
|
||||
if (!validatedHotelData.success) {
|
||||
console.error(
|
||||
"api.hotels.rates validation error ",
|
||||
JSON.stringify(validatedHotelData.error)
|
||||
"api.hotels.rates validation error",
|
||||
JSON.stringify({
|
||||
error: validatedHotelData.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
console.info("api.hotels.rates success")
|
||||
console.info("api.hotels.rates success", JSON.stringify({}))
|
||||
return validatedHotelData.data
|
||||
}),
|
||||
getFilters: publicProcedure
|
||||
.input(getFiltersInputSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
console.info("api.hotels.filters start")
|
||||
console.info("api.hotels.filters start", JSON.stringify({}))
|
||||
|
||||
if (!tempFilterData) {
|
||||
console.error("api.hotels.filters error, ", {})
|
||||
console.error(
|
||||
"api.hotels.filters error",
|
||||
JSON.stringify({ error: null })
|
||||
)
|
||||
//Can't return null here since consuming component does not handle null yet
|
||||
// return null
|
||||
}
|
||||
@@ -123,11 +152,13 @@ export const hotelQueryRouter = router({
|
||||
if (!validateFilterData.success) {
|
||||
console.error(
|
||||
"api.hotels.filters validation error",
|
||||
JSON.stringify(validateFilterData.error)
|
||||
JSON.stringify({
|
||||
error: validateFilterData.error,
|
||||
})
|
||||
)
|
||||
throw badRequestError()
|
||||
}
|
||||
|
||||
console.info("api.hotels.rates success", JSON.stringify({}))
|
||||
return validateFilterData.data
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -42,7 +42,7 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
||||
if (session.token.expires_at && session.token.expires_at < now) {
|
||||
return { error: true, cause: "token_expired" } as const
|
||||
}
|
||||
console.info("api.user.profile start,")
|
||||
console.info("api.user.profile start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
@@ -51,7 +51,12 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
||||
})
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
console.error("api.user.profile error ", JSON.stringify(apiResponse))
|
||||
console.error(
|
||||
"api.user.profile error",
|
||||
JSON.stringify({
|
||||
error: apiResponse,
|
||||
})
|
||||
)
|
||||
if (apiResponse.status === 401) {
|
||||
return { error: true, cause: "unauthorized" } as const
|
||||
} else if (apiResponse.status === 403) {
|
||||
@@ -68,16 +73,16 @@ async function getVerifiedUser({ session }: { session: Session }) {
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
if (!apiJson.data?.attributes) {
|
||||
console.error("api.user.profile data error")
|
||||
console.error("api.user.profile data error", JSON.stringify({})) // not passing the data to avoid logging sensitive data
|
||||
return null
|
||||
}
|
||||
|
||||
const verifiedData = getUserSchema.safeParse(apiJson.data.attributes)
|
||||
if (!verifiedData.success) {
|
||||
console.error("api.user.profile validation error")
|
||||
console.error("api.user.profile validation error", JSON.stringify({})) // not passing the data to avoid logging sensitive data
|
||||
return null
|
||||
}
|
||||
console.info("api.user.profile success")
|
||||
console.info("api.user.profile success", JSON.stringify({}))
|
||||
return verifiedData
|
||||
}
|
||||
|
||||
@@ -107,7 +112,7 @@ async function updateStaysBookingUrl(
|
||||
lang: Lang
|
||||
) {
|
||||
// Tenporary API call needed till we have user name in ctx session data
|
||||
console.info("api.user.profile start")
|
||||
console.info("api.user.profile start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
@@ -144,7 +149,7 @@ async function updateStaysBookingUrl(
|
||||
}
|
||||
|
||||
if (apiResponse.ok) {
|
||||
console.info("api.user.profile success")
|
||||
console.info("api.user.profile success", JSON.stringify({}))
|
||||
const apiJson = await apiResponse.json()
|
||||
if (apiJson.data?.attributes) {
|
||||
return data.map((d) => {
|
||||
@@ -170,7 +175,7 @@ async function updateStaysBookingUrl(
|
||||
})
|
||||
}
|
||||
}
|
||||
console.info("api.user.profile error", JSON.stringify(apiResponse))
|
||||
console.info("api.user.profile error", JSON.stringify({ error: apiResponse }))
|
||||
|
||||
return data
|
||||
}
|
||||
@@ -281,7 +286,10 @@ export const userQueryRouter = router({
|
||||
const params = new URLSearchParams()
|
||||
params.set("limit", "1")
|
||||
|
||||
console.info("api.booking.stays.past start")
|
||||
console.info(
|
||||
"api.booking.stays.past start",
|
||||
JSON.stringify({ query: { params } })
|
||||
)
|
||||
const previousStaysResponse = await api.get(
|
||||
api.endpoints.v1.previousStays,
|
||||
{
|
||||
@@ -294,8 +302,8 @@ export const userQueryRouter = router({
|
||||
|
||||
if (!previousStaysResponse.ok) {
|
||||
console.error(
|
||||
"api.booking.stays.past error ",
|
||||
JSON.stringify(previousStaysResponse)
|
||||
"api.booking.stays.past error",
|
||||
JSON.stringify({ error: previousStaysResponse })
|
||||
)
|
||||
return notLoggedInUserTrackingData
|
||||
}
|
||||
@@ -306,11 +314,11 @@ export const userQueryRouter = router({
|
||||
if (!verifiedPreviousStaysData.success) {
|
||||
console.error(
|
||||
"api.booking.stays.past validation error, ",
|
||||
JSON.stringify(verifiedPreviousStaysData.error)
|
||||
JSON.stringify({ error: verifiedPreviousStaysData.error })
|
||||
)
|
||||
return notLoggedInUserTrackingData
|
||||
}
|
||||
console.info("api.booking.stays.past success")
|
||||
console.info("api.booking.stays.past success", JSON.stringify({}))
|
||||
|
||||
const membership = getMembership(verifiedUserData.data.memberships)
|
||||
|
||||
@@ -345,7 +353,10 @@ export const userQueryRouter = router({
|
||||
if (cursor) {
|
||||
params.offset = cursor
|
||||
}
|
||||
console.info("api.booking.stays.past start")
|
||||
console.info(
|
||||
"api.booking.stays.past start",
|
||||
JSON.stringify({ query: { params: params.toString() } })
|
||||
)
|
||||
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.previousStays,
|
||||
@@ -370,7 +381,10 @@ export const userQueryRouter = router({
|
||||
// }
|
||||
console.error(
|
||||
"api.booking.stays.past error ",
|
||||
JSON.stringify(apiResponse)
|
||||
JSON.stringify({
|
||||
query: { params: params.toString() },
|
||||
error: apiResponse,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -381,12 +395,18 @@ export const userQueryRouter = router({
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.booking.stays.past validation error ",
|
||||
JSON.stringify(verifiedData.error)
|
||||
JSON.stringify({
|
||||
query: { params: params.toString() },
|
||||
error: verifiedData.error,
|
||||
})
|
||||
)
|
||||
|
||||
return null
|
||||
}
|
||||
console.info("api.booking.stays.past success")
|
||||
console.info(
|
||||
"api.booking.stays.past success",
|
||||
JSON.stringify({ query: { params: params.toString() } })
|
||||
)
|
||||
const nextCursor =
|
||||
verifiedData.data.links &&
|
||||
verifiedData.data.links.offset < verifiedData.data.links.totalCount
|
||||
@@ -414,7 +434,10 @@ export const userQueryRouter = router({
|
||||
if (cursor) {
|
||||
params.offset = cursor
|
||||
}
|
||||
console.info("api.booking.stays.future start")
|
||||
console.info(
|
||||
"api.booking.stays.future start",
|
||||
JSON.stringify({ query: { params: params.toString() } })
|
||||
)
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v1.upcomingStays,
|
||||
{
|
||||
@@ -438,7 +461,10 @@ export const userQueryRouter = router({
|
||||
// }
|
||||
console.error(
|
||||
"api.booking.stays.future error ",
|
||||
JSON.stringify(apiResponse)
|
||||
JSON.stringify({
|
||||
query: { params: params.toString() },
|
||||
error: apiResponse,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -448,11 +474,16 @@ export const userQueryRouter = router({
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.booking.stays.future validation error ",
|
||||
JSON.stringify(verifiedData.error)
|
||||
JSON.stringify({
|
||||
query: { params: params.toString() },
|
||||
error: verifiedData.error,
|
||||
})
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("api.booking.stays.future success")
|
||||
console.info("api.booking.stays.future success", {
|
||||
query: { params: params.toString() },
|
||||
})
|
||||
const nextCursor =
|
||||
verifiedData.data.links &&
|
||||
verifiedData.data.links.offset < verifiedData.data.links.totalCount
|
||||
@@ -476,7 +507,10 @@ export const userQueryRouter = router({
|
||||
.input(friendTransactionsInput)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const { limit, page } = input
|
||||
console.info("api.transaction.friendTransactions start")
|
||||
console.info(
|
||||
"api.transaction.friendTransactions start",
|
||||
JSON.stringify({})
|
||||
)
|
||||
const apiResponse = await api.get(api.endpoints.v1.friendTransactions, {
|
||||
cache: undefined, // override defaultOptions
|
||||
headers: {
|
||||
@@ -498,7 +532,7 @@ export const userQueryRouter = router({
|
||||
// }
|
||||
console.error(
|
||||
"api.transaction.friendTransactions error ",
|
||||
JSON.stringify(apiResponse)
|
||||
JSON.stringify({ error: apiResponse })
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -508,12 +542,15 @@ export const userQueryRouter = router({
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.transaction.friendTransactions validation error ",
|
||||
JSON.stringify(verifiedData.error)
|
||||
JSON.stringify({ error: verifiedData.error })
|
||||
)
|
||||
return null
|
||||
}
|
||||
|
||||
console.info("api.transaction.friendTransactions success")
|
||||
console.info(
|
||||
"api.transaction.friendTransactions success",
|
||||
JSON.stringify({})
|
||||
)
|
||||
const updatedData = await updateStaysBookingUrl(
|
||||
verifiedData.data.data,
|
||||
ctx.session.token.access_token,
|
||||
@@ -580,7 +617,7 @@ export const userQueryRouter = router({
|
||||
}),
|
||||
|
||||
creditCards: protectedProcedure.query(async function ({ ctx }) {
|
||||
console.info("api.profile.creditCards start")
|
||||
console.info("api.profile.creditCards start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v1.creditCards, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
@@ -591,7 +628,7 @@ export const userQueryRouter = router({
|
||||
if (!apiResponse.ok) {
|
||||
console.error(
|
||||
"api.profile.creditCards error ",
|
||||
JSON.stringify(apiResponse)
|
||||
JSON.stringify({ error: apiResponse })
|
||||
)
|
||||
return null
|
||||
}
|
||||
@@ -601,16 +638,16 @@ export const userQueryRouter = router({
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.profile.creditCards validation error ",
|
||||
JSON.stringify(verifiedData.error)
|
||||
JSON.stringify({ error: verifiedData.error })
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("api.profile.creditCards success")
|
||||
console.info("api.profile.creditCards success", JSON.stringify({}))
|
||||
return verifiedData.data.data
|
||||
}),
|
||||
|
||||
membershipCards: protectedProcedure.query(async function ({ ctx }) {
|
||||
console.info("api.profile start")
|
||||
console.info("api.profile start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v1.profile, {
|
||||
cache: "no-store",
|
||||
headers: {
|
||||
@@ -629,7 +666,7 @@ export const userQueryRouter = router({
|
||||
// default:
|
||||
// throw internalServerError()
|
||||
// }
|
||||
console.log("api.profile error ", JSON.stringify(apiResponse))
|
||||
console.log("api.profile error", JSON.stringify({ error: apiResponse }))
|
||||
}
|
||||
|
||||
const apiJson = await apiResponse.json()
|
||||
@@ -640,12 +677,12 @@ export const userQueryRouter = router({
|
||||
|
||||
if (!verifiedData.success) {
|
||||
console.error(
|
||||
"api.profile validation error ",
|
||||
JSON.stringify(verifiedData)
|
||||
"api.profile validation error",
|
||||
JSON.stringify({ error: verifiedData })
|
||||
)
|
||||
return null
|
||||
}
|
||||
console.info("api.profile success")
|
||||
console.info("api.profile success", JSON.stringify({}))
|
||||
const cards = getMembershipCards(verifiedData.data)
|
||||
|
||||
return cards
|
||||
|
||||
Reference in New Issue
Block a user