refactor: replace string literals with table constants in TaskRepository
This commit is contained in:
@@ -21,11 +21,11 @@ class TaskRepository {
|
|||||||
try {
|
try {
|
||||||
// 1. FASE FILTRI: Usa il join esplicito stile "Notes"
|
// 1. FASE FILTRI: Usa il join esplicito stile "Notes"
|
||||||
var filterBuilder = _supabase
|
var filterBuilder = _supabase
|
||||||
.from('tasks')
|
.from(Tables.tasks)
|
||||||
.select('''
|
.select('''
|
||||||
*,
|
*,
|
||||||
task_assignments (
|
${Tables.taskAssignments} (
|
||||||
staff_members (*)
|
${Tables.staffMembers} (*)
|
||||||
)
|
)
|
||||||
''')
|
''')
|
||||||
.eq('company_id', companyId);
|
.eq('company_id', companyId);
|
||||||
@@ -76,7 +76,7 @@ class TaskRepository {
|
|||||||
|
|
||||||
// 1. Inseriamo il record base nella tabella tasks
|
// 1. Inseriamo il record base nella tabella tasks
|
||||||
final response = await _supabase
|
final response = await _supabase
|
||||||
.from('tasks')
|
.from(Tables.tasks)
|
||||||
.insert(taskData)
|
.insert(taskData)
|
||||||
.select()
|
.select()
|
||||||
.single();
|
.single();
|
||||||
@@ -110,7 +110,7 @@ class TaskRepository {
|
|||||||
); // Sempre via l'array dal body principale
|
); // Sempre via l'array dal body principale
|
||||||
|
|
||||||
// 1. Aggiorniamo i dati base del task (titolo, stato, scadenza, ecc.)
|
// 1. Aggiorniamo i dati base del task (titolo, stato, scadenza, ecc.)
|
||||||
await _supabase.from('tasks').update(taskData).eq('id', task.id!);
|
await _supabase.from(Tables.tasks).update(taskData).eq('id', task.id!);
|
||||||
|
|
||||||
// 2. Sincronizziamo in modo distruttivo gli assegnatari nella tabella di giunzione
|
// 2. Sincronizziamo in modo distruttivo gli assegnatari nella tabella di giunzione
|
||||||
await _syncAssignments(task.id!, task.assignedToIds);
|
await _syncAssignments(task.id!, task.assignedToIds);
|
||||||
@@ -127,7 +127,7 @@ class TaskRepository {
|
|||||||
try {
|
try {
|
||||||
// Eliminando il task, se la Foreign Key su Supabase ha "ON DELETE CASCADE",
|
// Eliminando il task, se la Foreign Key su Supabase ha "ON DELETE CASCADE",
|
||||||
// le righe nella tabella di giunzione si distruggeranno da sole in automatico!
|
// le righe nella tabella di giunzione si distruggeranno da sole in automatico!
|
||||||
await _supabase.from('tasks').delete().eq('id', taskId);
|
await _supabase.from(Tables.tasks).delete().eq('id', taskId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Errore nell\'eliminazione del task: $e');
|
throw Exception('Errore nell\'eliminazione del task: $e');
|
||||||
}
|
}
|
||||||
@@ -137,8 +137,10 @@ class TaskRepository {
|
|||||||
Future<TaskModel> getTaskById(String taskId) async {
|
Future<TaskModel> getTaskById(String taskId) async {
|
||||||
try {
|
try {
|
||||||
final response = await _supabase
|
final response = await _supabase
|
||||||
.from('tasks')
|
.from(Tables.tasks)
|
||||||
.select('*, assigned_to_staff:staff_members!task_assignments(*)')
|
.select(
|
||||||
|
'*, assigned_to_staff:${Tables.staffMembers}!${Tables.taskAssignments}(*)',
|
||||||
|
)
|
||||||
.eq('id', taskId)
|
.eq('id', taskId)
|
||||||
.single();
|
.single();
|
||||||
return TaskModel.fromMap(response);
|
return TaskModel.fromMap(response);
|
||||||
@@ -154,7 +156,7 @@ class TaskRepository {
|
|||||||
// di questo task e li reinseriamo. È fulmineo ed esclude a priori bug di disallineamento.
|
// di questo task e li reinseriamo. È fulmineo ed esclude a priori bug di disallineamento.
|
||||||
|
|
||||||
// 1. Facciamo piazza pulita
|
// 1. Facciamo piazza pulita
|
||||||
await _supabase.from('task_assignments').delete().eq('task_id', taskId);
|
await _supabase.from(Tables.taskAssignments).delete().eq('task_id', taskId);
|
||||||
|
|
||||||
// 2. Inseriamo le nuove assegnazioni (se ce ne sono)
|
// 2. Inseriamo le nuove assegnazioni (se ce ne sono)
|
||||||
if (staffIds.isNotEmpty) {
|
if (staffIds.isNotEmpty) {
|
||||||
@@ -162,7 +164,7 @@ class TaskRepository {
|
|||||||
.map((staffId) => {'task_id': taskId, 'staff_id': staffId})
|
.map((staffId) => {'task_id': taskId, 'staff_id': staffId})
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
await _supabase.from('task_assignments').insert(assignments);
|
await _supabase.from(Tables.taskAssignments).insert(assignments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user