* 快速删除任务 * * 1. 原子标记 Task 为 deletedAt,使普通列表立即隐藏 * 2. 保存后台清理快照 * 3. 通过 EventBus 通知前端实时删除 * 4. 后台 worker 再停止 Session、删除 worktree/branch,并最终硬删除 Task
(id: string)
| 569 | [TaskStatus.IN_REVIEW]: 1, |
| 570 | [TaskStatus.TODO]: 2, |
| 571 | [TaskStatus.DONE]: 3, |
| 572 | [TaskStatus.CANCELLED]: 4, |
| 573 | }; |
| 574 | |
| 575 | const [data, total] = await Promise.all([ |
| 576 | prisma.task.findMany({ |
| 577 | where, |
| 578 | select: { |
| 579 | id: true, |
| 580 | projectId: true, |
| 581 | title: true, |
| 582 | status: true, |
| 583 | priority: true, |
| 584 | position: true, |
| 585 | createdAt: true, |
| 586 | updatedAt: true, |
| 587 | workspaces: { include: { sessions: visibleSessionSummary } }, |
| 588 | project: true, |
| 589 | }, |
| 590 | orderBy: [{ updatedAt: 'desc' }], |
| 591 | skip, |
| 592 | take: limit, |
| 593 | }), |
| 594 | prisma.task.count({ where }), |
| 595 | ]); |
| 596 | |
| 597 | data.sort((a, b) => { |
| 598 | const sa = statusOrder[a.status] ?? 99; |
| 599 | const sb = statusOrder[b.status] ?? 99; |
| 600 | if (sa !== sb) return sa - sb; |
| 601 | return (a.position ?? 0) - (b.position ?? 0); |
| 602 | }); |
| 603 | |
| 604 | const projectGitCapability = getStoredProjectGitCapability(project); |
| 605 | |
| 606 | return { |
| 607 | data: data.map((task) => ( |
| 608 | withTaskPreviews(withProjectGitCapability(task, projectGitCapability), { omitDescription: true }) |
| 609 | )), |
| 610 | total, |
| 611 | page, |
| 612 | limit, |
| 613 | totalPages: Math.ceil(total / limit), |
| 614 | }; |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * 获取任务详情 |
| 619 | */ |
| 620 | async findById(id: string) { |
| 621 | const task = await prisma.task.findFirst({ |
| 622 | where: { id, deletedAt: null }, |
| 623 | select: { |
| 624 | id: true, |
| 625 | projectId: true, |
| 626 | project: true, |
| 627 | title: true, |
| 628 | status: true, |