fix supabase storage

This commit is contained in:
2026-04-20 16:50:55 +02:00
parent 8dc1c661ed
commit de940cea1f
10 changed files with 172 additions and 100 deletions

View File

@@ -18,7 +18,7 @@ class CustomerRepository {
.upsert(customer.toJson())
.select()
.single();
return CustomerModel.fromJson(response);
return CustomerModel.fromMap(response);
} catch (e) {
throw 'Errore durante il salvataggio del cliente: $e';
}
@@ -32,7 +32,7 @@ class CustomerRepository {
.eq('id', customer.id!)
.select()
.single();
return CustomerModel.fromJson(response);
return CustomerModel.fromMap(response);
} catch (e) {
throw 'Errore durante la modifica del cliente: $e';
}
@@ -43,12 +43,15 @@ class CustomerRepository {
try {
final response = await _supabase
.from('customer')
.select('*, customer_file(count)')
.select('''
*,
customer_file(*)
''')
.eq('company_id', companyId)
.eq('is_active', true)
.order('nome');
return (response as List).map((c) => CustomerModel.fromJson(c)).toList();
return (response as List).map((c) => CustomerModel.fromMap(c)).toList();
} catch (e) {
throw 'Errore nel recupero clienti';
}
@@ -67,7 +70,7 @@ class CustomerRepository {
.or('nome.ilike.%$query%,telefono.ilike.%$query%')
.limit(10);
return (response as List).map((c) => CustomerModel.fromJson(c)).toList();
return (response as List).map((c) => CustomerModel.fromMap(c)).toList();
} catch (e) {
return [];
}
@@ -110,7 +113,7 @@ class CustomerRepository {
customerId: customerId,
name: cleanFileName.fileNameWithoutExtension(),
extension: cleanFileName.fileExtension(),
url: '',
url: storagePath,
fileSize: fileSize,
);
final String mimeType = fileToSave.extension.toLowerCase() == 'pdf'
@@ -133,13 +136,9 @@ class CustomerRepository {
);
}
final String publicUrl = _supabase.storage
.from('documents')
.getPublicUrl(storagePath);
final response = await _supabase
.from('customer_file')
.insert(fileToSave.copyWith(url: publicUrl).toMap())
.insert(fileToSave.toMap())
.select()
.single();