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
28 lines
791 B
TypeScript
28 lines
791 B
TypeScript
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
|
|
}
|