mirror of
https://github.com/Since-3/since3-portal.git
synced 2026-10-12 21:41:16 +00:00
29 lines
1 KiB
TypeScript
29 lines
1 KiB
TypeScript
import "server-only"
|
|
import { createAdminClient } from "@/lib/supabase/admin"
|
|
|
|
export type MailRecipient = { email: string; name: string | null }
|
|
|
|
// Mails gehen an den Ansprechpartner aus den Stammdaten; ohne Stammdaten an die Login-Email.
|
|
// Nur nach erfolgter Berechtigungsprüfung aufrufen (Service-Role umgeht RLS).
|
|
export async function getMailRecipient(profileId: string): Promise<MailRecipient | null> {
|
|
const supabase = createAdminClient()
|
|
const { data: profile } = await supabase
|
|
.from("profiles")
|
|
.select("email, name, client_id")
|
|
.eq("id", profileId)
|
|
.maybeSingle()
|
|
|
|
if (!profile) return null
|
|
|
|
if (profile.client_id) {
|
|
const { data: client } = await supabase
|
|
.from("clients")
|
|
.select("contact_name, contact_email")
|
|
.eq("id", profile.client_id)
|
|
.maybeSingle()
|
|
|
|
if (client?.contact_email) return { email: client.contact_email, name: client.contact_name ?? null }
|
|
}
|
|
|
|
return { email: profile.email, name: profile.name ?? null }
|
|
}
|