Auto Task Assignment

This commit is contained in:
2026-02-18 23:14:50 +08:00
parent 372928d8e7
commit 5ec57a1cec
12 changed files with 1109 additions and 138 deletions
+34
View File
@@ -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
}
}
}
}