Archive or unarchive a task, or batch-archive all Done/Cancelled tasks.
(task_id, archived, archive_all_done=False)
| 247 | |
| 248 | |
| 249 | def handle_archive_task(task_id, archived, archive_all_done=False): |
| 250 | """Archive or unarchive a task, or batch-archive all Done/Cancelled tasks.""" |
| 251 | tasks = load_tasks() |
| 252 | if archive_all_done: |
| 253 | count = 0 |
| 254 | for t in tasks: |
| 255 | if t.get('state') in ('Done', 'Cancelled') and not t.get('archived'): |
| 256 | t['archived'] = True |
| 257 | t['archivedAt'] = now_iso() |
| 258 | count += 1 |
| 259 | save_tasks(tasks) |
| 260 | return {'ok': True, 'message': f'{count} 道旨意已归档', 'count': count} |
| 261 | task = next((t for t in tasks if t.get('id') == task_id), None) |
| 262 | if not task: |
| 263 | return {'ok': False, 'error': f'任务 {task_id} 不存在'} |
| 264 | task['archived'] = archived |
| 265 | if archived: |
| 266 | task['archivedAt'] = now_iso() |
| 267 | else: |
| 268 | task.pop('archivedAt', None) |
| 269 | task['updatedAt'] = now_iso() |
| 270 | save_tasks(tasks) |
| 271 | label = '已归档' if archived else '已取消归档' |
| 272 | return {'ok': True, 'message': f'{task_id} {label}'} |
| 273 | |
| 274 | |
| 275 | def update_task_todos(task_id, todos): |
no test coverage detected