since3-portal/modules/templates/queries/variants.ts
2026-10-05 08:23:02 +02:00

41 lines
1.2 KiB
TypeScript

import "server-only"
import * as z from "zod"
import { createClient } from "@/lib/supabase/server"
export type VariantRow = {
id: string
name: string
template_key: string
client_id: string | null
content: unknown
share_token: string | null
share_expires_at: string | null
updated_at: string
}
export type VariantListItem = Omit<VariantRow, "content">
export async function getVariants() {
const supabase = await createClient()
const { data, error } = await supabase
.from("template_variants")
.select("id, name, template_key, client_id, share_token, share_expires_at, updated_at")
.order("updated_at", { ascending: false })
if (error) throw new Error(`Failed to load template variants: ${error.message}`)
return data as VariantListItem[]
}
export async function getVariant(id: string) {
if (!z.string().uuid().safeParse(id).success) return null
const supabase = await createClient()
const { data } = await supabase
.from("template_variants")
.select("id, name, template_key, client_id, content, share_token, share_expires_at, updated_at")
.eq("id", id)
.maybeSingle()
return data as VariantRow | null
}