feat(08-02): add smartDeleteTask to TaskActions provider

- Checks completion count before deleting
- Hard-deletes tasks with 0 completions
- Soft-deletes (isActive=false) tasks with completions
- Keeps existing deleteTask method for cascade/other uses
This commit is contained in:
2026-03-18 21:00:29 +01:00
parent 3bfa411d29
commit 1b1b981dac
2 changed files with 12 additions and 1 deletions

View File

@@ -89,4 +89,15 @@ class TaskActions extends _$TaskActions {
final db = ref.read(appDatabaseProvider);
await db.tasksDao.completeTask(taskId);
}
/// Smart delete: hard-deletes tasks with no completions, soft-deletes tasks with completions.
Future<void> smartDeleteTask(int taskId) async {
final db = ref.read(appDatabaseProvider);
final completionCount = await db.tasksDao.getCompletionCount(taskId);
if (completionCount == 0) {
await db.tasksDao.deleteTask(taskId);
} else {
await db.tasksDao.softDeleteTask(taskId);
}
}
}