since3-portal/modules/shared/queries/stammdaten.ts
2026-09-28 15:53:52 +02:00

25 lines
838 B
TypeScript

import "server-only"
import { createAdminClient } from "@/lib/supabase/admin"
export async function getStammdaten(profileId: string) {
const supabase = createAdminClient()
const { data: profile, error: profileError } = await supabase
.from("profiles")
.select("client_id")
.eq("id", profileId)
.single()
if (profileError || !profile) return null
if (!profile.client_id) {
return { client: null, paymentDetails: null }
}
const [{ data: client }, { data: paymentDetails }] = await Promise.all([
supabase.from("clients").select("*").eq("id", profile.client_id).single(),
supabase.from("client_payment_details").select("*").eq("client_id", profile.client_id).single(),
])
return { client: client ?? null, paymentDetails: paymentDetails ?? null }
}