From 8a9ce7ae0480237ee62a14c89d68eff87c2cd5b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Ben=C3=ADtez?= Date: Tue, 2 Jun 2026 23:27:11 -0300 Subject: [PATCH] fix --- src/persistence/supabase/settings-repo.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/persistence/supabase/settings-repo.ts b/src/persistence/supabase/settings-repo.ts index 23a2f0c..b3b21f0 100644 --- a/src/persistence/supabase/settings-repo.ts +++ b/src/persistence/supabase/settings-repo.ts @@ -5,12 +5,21 @@ const DEFAULT_SETTINGS: AppSettings = { id: 'singleton', groupLabel: 'Cliente' } export const supabaseSettingsRepo = { async get(): Promise { - const { data } = await supabase + const { data, error } = await supabase .from('app_settings') .select('id, group_label') .eq('id', 'singleton') .single() - if (!data) return DEFAULT_SETTINGS + + // PGRST116 = 0 rows — singleton aún no existe, crearlo y retornar el default + if (error?.code === 'PGRST116' || !data) { + await supabase.from('app_settings').upsert({ + id: 'singleton', + group_label: 'Cliente', + }) + return DEFAULT_SETTINGS + } + return { id: 'singleton', groupLabel: (data.group_label as string) ?? 'Cliente' } },