Auto Task Assignment
This commit is contained in:
@@ -10,6 +10,7 @@ import '../models/ticket_message.dart';
|
||||
import 'profile_provider.dart';
|
||||
import 'supabase_provider.dart';
|
||||
import 'user_offices_provider.dart';
|
||||
import 'tasks_provider.dart';
|
||||
|
||||
final officesProvider = StreamProvider<List<Office>>((ref) {
|
||||
final client = ref.watch(supabaseClientProvider);
|
||||
@@ -334,6 +335,39 @@ class TicketsController {
|
||||
required String status,
|
||||
}) async {
|
||||
await _client.from('tickets').update({'status': status}).eq('id', ticketId);
|
||||
|
||||
// If ticket is promoted, create a linked Task (only once) — the
|
||||
// TasksController.createTask already runs auto-assignment on creation.
|
||||
if (status == 'promoted') {
|
||||
try {
|
||||
final existing = await _client
|
||||
.from('tasks')
|
||||
.select('id')
|
||||
.eq('ticket_id', ticketId)
|
||||
.maybeSingle();
|
||||
if (existing != null) return;
|
||||
|
||||
final ticketRow = await _client
|
||||
.from('tickets')
|
||||
.select('subject, description, office_id')
|
||||
.eq('id', ticketId)
|
||||
.maybeSingle();
|
||||
|
||||
final title = (ticketRow?['subject'] as String?) ?? 'Task from ticket';
|
||||
final description = (ticketRow?['description'] as String?) ?? '';
|
||||
final officeId = ticketRow?['office_id'] as String?;
|
||||
|
||||
final tasksCtrl = TasksController(_client);
|
||||
await tasksCtrl.createTask(
|
||||
title: title,
|
||||
description: description,
|
||||
officeId: officeId,
|
||||
ticketId: ticketId,
|
||||
);
|
||||
} catch (_) {
|
||||
// best-effort — don't fail the ticket status update
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user