This commit is contained in:
2026-06-02 23:27:11 -03:00
parent 2955399ade
commit 8a9ce7ae04

View File

@@ -5,12 +5,21 @@ const DEFAULT_SETTINGS: AppSettings = { id: 'singleton', groupLabel: 'Cliente' }
export const supabaseSettingsRepo = { export const supabaseSettingsRepo = {
async get(): Promise<AppSettings> { async get(): Promise<AppSettings> {
const { data } = await supabase const { data, error } = await supabase
.from('app_settings') .from('app_settings')
.select('id, group_label') .select('id, group_label')
.eq('id', 'singleton') .eq('id', 'singleton')
.single() .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' } return { id: 'singleton', groupLabel: (data.group_label as string) ?? 'Cliente' }
}, },