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:
Anton Gunnarsson
2025-04-08 11:03:38 +00:00
parent d30cc7e2be
commit 5cb19dfccd
5 changed files with 62 additions and 13 deletions

View File

@@ -28,6 +28,7 @@ export const sasMembershipSchema = z
type: z.literal("SAS_EB"),
tier: sasEurobonusTier,
nextTier: sasEurobonusTier.nullish(),
spendablePoints: z.number().nullish(),
})
.merge(commonMembershipSchema)

View File

@@ -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