fix
This commit is contained in:
@@ -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' }
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user