Merged in feat/sw-1313-show-sas-points (pull request #1682)
SW-1313 - Add support for getting SAS EB points Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -82,18 +82,30 @@ const getCreditCardsFailCounter = meter.createCounter(
|
||||
)
|
||||
|
||||
export const getVerifiedUser = cache(
|
||||
async ({ session }: { session: Session }) => {
|
||||
async ({
|
||||
session,
|
||||
includeExtendedPartnerData,
|
||||
}: {
|
||||
session: Session
|
||||
includeExtendedPartnerData?: boolean
|
||||
}) => {
|
||||
const now = Date.now()
|
||||
if (session.token.expires_at && session.token.expires_at < now) {
|
||||
return { error: true, cause: "token_expired" } as const
|
||||
}
|
||||
getVerifiedUserCounter.add(1)
|
||||
console.info("api.user.profile getVerifiedUser start", JSON.stringify({}))
|
||||
const apiResponse = await api.get(api.endpoints.v2.Profile.profile, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${session.token.access_token}`,
|
||||
const apiResponse = await api.get(
|
||||
api.endpoints.v2.Profile.profile,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${session.token.access_token}`,
|
||||
},
|
||||
},
|
||||
})
|
||||
includeExtendedPartnerData
|
||||
? { includes: "extendedPartnerInformation" }
|
||||
: {}
|
||||
)
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
@@ -318,6 +330,24 @@ export const userQueryRouter = router({
|
||||
|
||||
return parsedUser(data.data, true)
|
||||
}),
|
||||
getWithExtendedPartnerData: safeProtectedProcedure.query(
|
||||
async function getUser({ ctx }) {
|
||||
if (!isValidSession(ctx.session)) {
|
||||
return null
|
||||
}
|
||||
|
||||
const data = await getVerifiedUser({
|
||||
session: ctx.session,
|
||||
includeExtendedPartnerData: true,
|
||||
})
|
||||
|
||||
if (!data || "error" in data) {
|
||||
return null
|
||||
}
|
||||
|
||||
return parsedUser(data.data, true)
|
||||
}
|
||||
),
|
||||
name: safeProtectedProcedure.query(async function ({ ctx }) {
|
||||
if (!isValidSession(ctx.session)) {
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user