Q150: work can be sent back, reopened, moved to backlog, or blocked with a reason
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7ab46bb2de
commit
809c67a54a
21 files changed
+153
-7
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import type { DatabaseSync } from "node:sqlite";
|
||||
import { RISK_LEVEL, TASK_STATUS, type TaskPriority } from "../../shared/domain";
|
||||
import type { CreateTaskInput, DeleteTaskInput, UpdateTaskInput } from "../../shared/commands";
|
||||
import type { CreateTaskInput, DeleteTaskInput, SetTaskBlockedInput, UpdateTaskInput } from "../../shared/commands";
|
||||
import { AuditService } from "./audit-service";
|
||||
import { withSavepoint } from "../database/connection";
|
||||
import { heldWorkTitles } from "./held-deliverables";
|
||||
@@ -70,6 +70,26 @@ export class TaskMutations {
|
||||
});
|
||||
}
|
||||
|
||||
/** Blocks the task with a reason (no session starts, queued ones are superseded) or unblocks it with null. */
|
||||
setBlocked(input: SetTaskBlockedInput): void {
|
||||
const reason = input.reason === null ? null : input.reason.trim();
|
||||
if (reason === "") throw new Error("Say why the task is blocked.");
|
||||
withSavepoint(this.db, "task_block", () => {
|
||||
const result = this.db.prepare("update tasks set blocked_reason = ?, updated_at = ? where id = ? and org_id = ?").run(reason, new Date().toISOString(), input.taskId, input.orgId);
|
||||
if (result.changes === 0) throw new Error("Task was not found.");
|
||||
if (reason !== null) {
|
||||
this.db.prepare(`
|
||||
update task_runs set state = 'superseded', completed_at = ?, error_message = ?
|
||||
where task_id = ? and org_id = ? and state = 'queued'
|
||||
`).run(new Date().toISOString(), `Superseded: the task was blocked (${reason}).`, input.taskId, input.orgId);
|
||||
}
|
||||
this.audit.record({
|
||||
orgId: input.orgId, entityType: "task", entityId: input.taskId, actorType: "employee", actorId: null,
|
||||
action: reason === null ? "unblocked" : "blocked", payload: { reason },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
delete(input: DeleteTaskInput): void {
|
||||
const running = this.db.prepare("select 1 from task_runs where task_id = ? and org_id = ? and state = 'running' limit 1")
|
||||
.get(input.taskId, input.orgId);
|
||||
|
||||
Reference in new issue
Block a user