fixes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/enums_and_consts/consts.dart';
|
||||
import 'package:flux/features/notes/models/note_model.dart';
|
||||
@@ -130,13 +131,26 @@ class NotesRepository {
|
||||
await _supabase.from('note_collaborators').delete().eq('note_id', noteId);
|
||||
|
||||
// 3. RE-INSERIMENTO DELLA LISTA AGGIORNATA
|
||||
// Se ci sono collaboratori da inserire, li prepariamo in blocco (Bulk Insert)
|
||||
if (note.collaboratorIds.isNotEmpty) {
|
||||
final collaboratorsToInsert = note.collaboratorIds
|
||||
.map((staffId) => {'note_id': noteId, 'staff_id': staffId})
|
||||
.map(
|
||||
(staffId) => {
|
||||
'note_id': noteId,
|
||||
'staff_id': staffId,
|
||||
'company_id': note.companyId, // Aggiunto questo!
|
||||
},
|
||||
)
|
||||
.toList();
|
||||
|
||||
await _supabase.from('note_collaborators').insert(collaboratorsToInsert);
|
||||
// Consiglio da pro: avvolgi l'insert in un try-catch per stampare l'errore esatto a console
|
||||
try {
|
||||
await _supabase
|
||||
.from(Tables.noteCollaborators)
|
||||
.insert(collaboratorsToInsert);
|
||||
} catch (e) {
|
||||
debugPrint('Errore inserimento collaboratori: $e');
|
||||
throw Exception('Impossibile aggiungere i collaboratori alla nota.');
|
||||
}
|
||||
}
|
||||
|
||||
// Restituiamo l'id alla UI (fondamentale per la nostra logica Ninja di creazione)
|
||||
|
||||
Reference in New Issue
Block a user