Merged in feat/SW-3526-show-sas-eb-points-rate-in- (pull request #2933)
feat(SW-3526): Show EB points rate and label in booking flow * feat(SW-3526): Show EB points rate and label in booking flow * feat(SW-3526) Optimized points currency code * feat(SW-3526) Removed extra multiplication for token expiry after rebase * feat(SW-3526): Updated to exhaustive check and thow if type error Approved-by: Anton Gunnarsson
This commit is contained in:
23
packages/trpc/lib/utils/getRedemptionTokenSafely.ts
Normal file
23
packages/trpc/lib/utils/getRedemptionTokenSafely.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { isValidSession } from "./session"
|
||||
|
||||
import type { Session } from "next-auth"
|
||||
|
||||
export function getRedemptionTokenSafely(
|
||||
session: Session,
|
||||
serviceToken: string
|
||||
): string | undefined {
|
||||
if (!isValidSession(session)) return undefined
|
||||
|
||||
// ToDo- Get Curity based token when linked user is logged in
|
||||
// const token =
|
||||
// session.token.loginType === "sas"
|
||||
// ? session.token.curity_access_token ?? serviceToken
|
||||
// : session.token.access_token
|
||||
|
||||
const token =
|
||||
session.token.loginType === "sas"
|
||||
? serviceToken
|
||||
: session.token.access_token
|
||||
|
||||
return token
|
||||
}
|
||||
27
packages/trpc/lib/utils/getUserPointsBalance.ts
Normal file
27
packages/trpc/lib/utils/getUserPointsBalance.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { getEuroBonusProfileData } from "../routers/partners/sas/getEuroBonusProfile"
|
||||
import { getVerifiedUser } from "../routers/user/utils/getVerifiedUser"
|
||||
import { isValidSession } from "./session"
|
||||
|
||||
import type { Session } from "next-auth"
|
||||
|
||||
export async function getUserPointsBalance(
|
||||
session: Session | null
|
||||
): Promise<number | undefined> {
|
||||
if (!isValidSession(session)) return undefined
|
||||
|
||||
const verifiedUser =
|
||||
session.token.loginType === "sas"
|
||||
? await getEuroBonusProfileData(session)
|
||||
: await getVerifiedUser({ session })
|
||||
|
||||
if (!verifiedUser || "error" in verifiedUser) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const points =
|
||||
"points" in verifiedUser.data
|
||||
? verifiedUser.data.points.total
|
||||
: verifiedUser.data.membership?.currentPoints
|
||||
|
||||
return points ?? 0
|
||||
}
|
||||
Reference in New Issue
Block a user