refactor nomi tabelle
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/enums_and_consts/consts.dart';
|
||||
import 'package:flux/core/utils/extensions.dart';
|
||||
import 'package:flux/features/attachments/models/attachment_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
@@ -14,7 +15,7 @@ class CustomerRepository {
|
||||
Future<CustomerModel> insertCustomer(CustomerModel customer) async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('customer')
|
||||
.from(Tables.customers)
|
||||
.upsert(customer.toJson())
|
||||
.select()
|
||||
.single();
|
||||
@@ -27,7 +28,7 @@ class CustomerRepository {
|
||||
Future<CustomerModel> updateCustomer(CustomerModel customer) async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('customer')
|
||||
.from(Tables.customers)
|
||||
.update(customer.toJson())
|
||||
.eq('id', customer.id!)
|
||||
.select()
|
||||
@@ -42,10 +43,10 @@ class CustomerRepository {
|
||||
Future<List<CustomerModel>> getCustomers(String companyId) async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('customer')
|
||||
.from(Tables.customers)
|
||||
.select('''
|
||||
*,
|
||||
attachment(*)
|
||||
${Tables.attachments}(*)
|
||||
''')
|
||||
.eq('company_id', companyId)
|
||||
.eq('is_active', true)
|
||||
@@ -60,10 +61,10 @@ class CustomerRepository {
|
||||
Future<CustomerModel> getCustomerById(String customerId) async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('customer')
|
||||
.from(Tables.customers)
|
||||
.select('''
|
||||
*,
|
||||
attachment(*)
|
||||
${Tables.attachments}(*)
|
||||
''')
|
||||
.eq('id', customerId)
|
||||
.single();
|
||||
@@ -81,7 +82,7 @@ class CustomerRepository {
|
||||
) async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('customer')
|
||||
.from(Tables.customers)
|
||||
.select()
|
||||
.eq('company_id', companyId)
|
||||
.or('name.ilike.%$query%,phone_number.ilike.%$query%')
|
||||
@@ -96,7 +97,7 @@ class CustomerRepository {
|
||||
/// Ascolta in tempo reale i file caricati per un cliente
|
||||
Stream<List<AttachmentModel>> getCustomerFilesStream(String customerId) {
|
||||
return _supabase
|
||||
.from('attachment')
|
||||
.from(Tables.attachments)
|
||||
.stream(primaryKey: ['id'])
|
||||
.eq('customer_id', customerId)
|
||||
.order('created_at', ascending: false)
|
||||
@@ -110,7 +111,7 @@ class CustomerRepository {
|
||||
Future<List<AttachmentModel>> getCustomerFiles(String customerId) async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('attachment')
|
||||
.from(Tables.attachments)
|
||||
.select()
|
||||
.eq('customer_id', customerId);
|
||||
|
||||
@@ -161,7 +162,7 @@ class CustomerRepository {
|
||||
}
|
||||
|
||||
final response = await _supabase
|
||||
.from('attachment')
|
||||
.from(Tables.attachments)
|
||||
.insert(fileToSave.toMap())
|
||||
.select()
|
||||
.single();
|
||||
@@ -173,7 +174,7 @@ class CustomerRepository {
|
||||
}
|
||||
|
||||
Future<void> saveFileReference(AttachmentModel file) async {
|
||||
await _supabase.from('attachment').upsert(file.toMap());
|
||||
await _supabase.from(Tables.attachments).upsert(file.toMap());
|
||||
}
|
||||
|
||||
Future<void> deleteDocuments(List<AttachmentModel> files) async {
|
||||
@@ -192,13 +193,16 @@ class CustomerRepository {
|
||||
}
|
||||
try {
|
||||
if (idsToDelete.isNotEmpty) {
|
||||
await _supabase.from('attachment').delete().inFilter('id', idsToDelete);
|
||||
await _supabase
|
||||
.from(Tables.attachments)
|
||||
.delete()
|
||||
.inFilter('id', idsToDelete);
|
||||
// 3. Cancellazione MASSIVA dallo Storage
|
||||
await _supabase.storage.from('documents').remove(storagePathsToDelete);
|
||||
}
|
||||
if (idsToEdit.isNotEmpty) {
|
||||
await _supabase
|
||||
.from('attachment')
|
||||
.from(Tables.attachments)
|
||||
.update({'customer_id': null})
|
||||
.inFilter('id', idsToEdit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user