Prevent task starting and completion without assigned it staff

This commit is contained in:
2026-03-02 20:22:42 +08:00
parent 43d2bd4f95
commit eb49329b16
2 changed files with 42 additions and 6 deletions
+30
View File
@@ -1102,6 +1102,36 @@ class TasksController {
}
if (status == 'completed') {
// Check for IT staff assignment
final assignmentRows = await _client
.from('task_assignments')
.select('user_id')
.eq('task_id', taskId);
final assignedUserIds = (assignmentRows as List)
.map((row) => row['user_id']?.toString())
.whereType<String>()
.where((id) => id.isNotEmpty)
.toSet()
.toList();
if (assignedUserIds.isEmpty) {
throw Exception(
'Assign at least one IT Staff before completing this task.',
);
}
final itStaffRows = await _client
.from('profiles')
.select('id')
.inFilter('id', assignedUserIds)
.eq('role', 'it_staff');
final hasItStaff = (itStaffRows as List).isNotEmpty;
if (!hasItStaff) {
throw Exception(
'Assign at least one IT Staff before completing this task.',
);
}
// Check required fields
try {
final rt = taskRow['request_type'];
final rc = taskRow['request_category'];