refactor nomi tabelle
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.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';
|
||||
@@ -15,15 +16,15 @@ class OperationsRepository {
|
||||
Future<OperationModel> fetchOperationById(String id) async {
|
||||
try {
|
||||
final response = await _supabase
|
||||
.from('operation')
|
||||
.from(Tables.operations)
|
||||
.select('''
|
||||
*,
|
||||
customer(*),
|
||||
store(name),
|
||||
staff_member(name),
|
||||
provider(name),
|
||||
model(name_with_brand),
|
||||
attachment(*)
|
||||
${Tables.customers}(*),
|
||||
${Tables.stores}(name),
|
||||
${Tables.staffMembers}(name),
|
||||
${Tables.providers}(name),
|
||||
${Tables.models}(name_with_brand),
|
||||
${Tables.attachments}(*)
|
||||
''')
|
||||
.eq('id', id)
|
||||
.single();
|
||||
@@ -44,15 +45,15 @@ class OperationsRepository {
|
||||
}) async {
|
||||
try {
|
||||
var query = _supabase
|
||||
.from('operation')
|
||||
.from(Tables.operations)
|
||||
.select('''
|
||||
*,
|
||||
customer(*),
|
||||
store(name),
|
||||
provider(name),
|
||||
model(name_with_brand),
|
||||
staff_member(name),
|
||||
attachment(*)
|
||||
${Tables.customers}(*),
|
||||
${Tables.stores}(name),
|
||||
${Tables.providers}(name),
|
||||
${Tables.models}(name_with_brand),
|
||||
${Tables.staffMembers}(name),
|
||||
${Tables.attachments}(*)
|
||||
''')
|
||||
.eq('company_id', companyId);
|
||||
|
||||
@@ -87,7 +88,7 @@ class OperationsRepository {
|
||||
required int limit,
|
||||
}) {
|
||||
return _supabase
|
||||
.from('operation')
|
||||
.from(Tables.operations)
|
||||
.stream(primaryKey: ['id'])
|
||||
.eq('store_id', storeId)
|
||||
.order('created_at', ascending: false)
|
||||
@@ -105,10 +106,10 @@ class OperationsRepository {
|
||||
try {
|
||||
// 1. Salvataggio classico dell'operazione corrente
|
||||
final response = await _supabase
|
||||
.from('operation')
|
||||
.from(Tables.operations)
|
||||
.upsert(operation.toMap())
|
||||
.select(
|
||||
'*, provider(*), model(*), store(*), staff_member(*), customer(*), attachment(*)',
|
||||
'*, ${Tables.providers}(*), ${Tables.models}(*), ${Tables.stores}(*), ${Tables.staffMembers}(*), ${Tables.customers}(*), ${Tables.attachments}(*)',
|
||||
)
|
||||
.single();
|
||||
|
||||
@@ -117,7 +118,7 @@ class OperationsRepository {
|
||||
// 2. ALLINEAMENTO BATCH SEMPRE ATTIVO!
|
||||
if (operation.batchUuid.isNotEmpty) {
|
||||
await _supabase
|
||||
.from('operation')
|
||||
.from(Tables.operations)
|
||||
.update({'note': operation.note}) // Spalmiamo la nota attuale
|
||||
.eq(
|
||||
'batch_uuid',
|
||||
@@ -134,7 +135,7 @@ class OperationsRepository {
|
||||
// --- ELIMINAZIONE ---
|
||||
Future<void> deleteOperation(String id) async {
|
||||
try {
|
||||
await _supabase.from('operation').delete().eq('id', id);
|
||||
await _supabase.from(Tables.operations).delete().eq('id', id);
|
||||
} catch (e) {
|
||||
throw Exception('$e');
|
||||
}
|
||||
@@ -146,7 +147,7 @@ class OperationsRepository {
|
||||
// Cerchiamo i tipi più frequenti associati ai servizi di questa company
|
||||
// Nota: dobbiamo passare attraverso la tabella 'operation' per filtrare per company_id
|
||||
final response = await _supabase
|
||||
.from('operation')
|
||||
.from(Tables.operations)
|
||||
.select('description')
|
||||
.eq('company_id', companyId)
|
||||
.eq('type', 'Entertainment')
|
||||
@@ -176,7 +177,7 @@ class OperationsRepository {
|
||||
/// Ascolta in tempo reale i file caricati per una pratica
|
||||
Stream<List<AttachmentModel>> getOperationFilesStream(String operationId) {
|
||||
return _supabase
|
||||
.from('attachment')
|
||||
.from(Tables.attachments)
|
||||
.stream(primaryKey: ['id'])
|
||||
.eq('operation_id', operationId)
|
||||
.order('created_at', ascending: false)
|
||||
@@ -226,7 +227,7 @@ class OperationsRepository {
|
||||
}
|
||||
|
||||
final response = await _supabase
|
||||
.from('attachment')
|
||||
.from(Tables.attachments)
|
||||
.insert(fileToSave.toMap())
|
||||
.select()
|
||||
.single();
|
||||
@@ -242,14 +243,17 @@ class OperationsRepository {
|
||||
required String customerId,
|
||||
}) async {
|
||||
await _supabase
|
||||
.from('attachment')
|
||||
.from(Tables.attachments)
|
||||
.update({'customer_id': customerId})
|
||||
.eq('id', file.id!);
|
||||
}
|
||||
|
||||
Future<void> renameAttachment(String id, String newName) async {
|
||||
try {
|
||||
await _supabase.from('attachment').update({'name': newName}).eq('id', id);
|
||||
await _supabase
|
||||
.from(Tables.attachments)
|
||||
.update({'name': newName})
|
||||
.eq('id', id);
|
||||
} catch (e) {
|
||||
throw '$e';
|
||||
}
|
||||
@@ -258,11 +262,11 @@ class OperationsRepository {
|
||||
Future<void> deleteSpecificOperationFile(AttachmentModel file) async {
|
||||
try {
|
||||
if (file.customerId == null) {
|
||||
await _supabase.from('attachment').delete().eq('id', file.id!);
|
||||
await _supabase.from(Tables.attachments).delete().eq('id', file.id!);
|
||||
await _supabase.storage.from('documents').remove([file.storagePath!]);
|
||||
} else {
|
||||
await _supabase
|
||||
.from('attachment')
|
||||
.from(Tables.attachments)
|
||||
.update({'operation_id': null})
|
||||
.eq('id', file.id!);
|
||||
}
|
||||
@@ -287,12 +291,15 @@ class OperationsRepository {
|
||||
}
|
||||
try {
|
||||
if (idsToDelete.isNotEmpty) {
|
||||
await _supabase.from('attachment').delete().inFilter('id', idsToDelete);
|
||||
await _supabase
|
||||
.from(Tables.attachments)
|
||||
.delete()
|
||||
.inFilter('id', idsToDelete);
|
||||
await _supabase.storage.from('documents').remove(storagePathsToDelete);
|
||||
}
|
||||
if (idsToEdit.isNotEmpty) {
|
||||
await _supabase
|
||||
.from('attachment')
|
||||
.from(Tables.attachments)
|
||||
.update({'operation_id': null})
|
||||
.inFilter('id', idsToEdit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user