feat/membershipcard: utilize memoiozed function to fetch membership cards
This commit is contained in:
@@ -778,51 +778,14 @@ export const userQueryRouter = router({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
membershipCards: protectedProcedure.query(async function ({ ctx }) {
|
membershipCards: protectedProcedure.query(async function ({ ctx }) {
|
||||||
getProfileCounter.add(1)
|
const userData = await getVerifiedUser({ session: ctx.session })
|
||||||
console.info("api.profile start", JSON.stringify({}))
|
|
||||||
const apiResponse = await api.get(api.endpoints.v1.Profile.profile, {
|
|
||||||
cache: "no-store",
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${ctx.session.token.access_token}`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!apiResponse.ok) {
|
if (!userData || "error" in userData) {
|
||||||
// switch (apiResponse.status) {
|
return null
|
||||||
// case 400:
|
|
||||||
// throw badRequestError()
|
|
||||||
// case 401:
|
|
||||||
// throw unauthorizedError()
|
|
||||||
// case 403:
|
|
||||||
// throw forbiddenError()
|
|
||||||
// default:
|
|
||||||
// throw internalServerError()
|
|
||||||
// }
|
|
||||||
const text = await apiResponse.text()
|
|
||||||
getProfileFailCounter.add(1, {
|
|
||||||
error_type: "http_error",
|
|
||||||
error: JSON.stringify({
|
|
||||||
status: apiResponse.status,
|
|
||||||
statusText: apiResponse.statusText,
|
|
||||||
text,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
console.error(
|
|
||||||
"api.profile error",
|
|
||||||
JSON.stringify({
|
|
||||||
error: {
|
|
||||||
status: apiResponse.status,
|
|
||||||
statusText: apiResponse.statusText,
|
|
||||||
text,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiJson = await apiResponse.json()
|
|
||||||
|
|
||||||
const verifiedData = getMembershipCardsSchema.safeParse(
|
const verifiedData = getMembershipCardsSchema.safeParse(
|
||||||
apiJson.data.attributes.memberships
|
userData.data.memberships
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!verifiedData.success) {
|
if (!verifiedData.success) {
|
||||||
@@ -837,9 +800,7 @@ export const userQueryRouter = router({
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
getProfileSuccessCounter.add(1)
|
getProfileSuccessCounter.add(1)
|
||||||
console.info("api.profile success", JSON.stringify({}))
|
|
||||||
const cards = getMembershipCards(verifiedData.data)
|
|
||||||
|
|
||||||
return cards
|
return getMembershipCards(verifiedData.data)
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user