summaryrefslogtreecommitdiff
path: root/makima/src/db/repository.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/db/repository.rs')
-rw-r--r--makima/src/db/repository.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs
index 27bd47e..b41c74c 100644
--- a/makima/src/db/repository.rs
+++ b/makima/src/db/repository.rs
@@ -1189,6 +1189,71 @@ pub async fn list_tasks_for_owner(
.await
}
+/// List ephemeral tasks attached to a directive — tasks with `directive_id`
+/// set but no `directive_step_id`. These are the "spinoff" tasks the user
+/// created via the directive folder context menu, distinct from
+/// step-spawned execution tasks. Hidden tasks excluded.
+pub async fn list_ephemeral_directive_tasks_for_owner(
+ pool: &PgPool,
+ owner_id: Uuid,
+ directive_id: Uuid,
+) -> Result<Vec<TaskSummary>, sqlx::Error> {
+ sqlx::query_as::<_, TaskSummary>(
+ r#"
+ SELECT
+ t.id, t.contract_id, c.name as contract_name, c.phase as contract_phase,
+ c.status as contract_status,
+ t.parent_task_id, t.depth, t.name, t.status, t.priority,
+ t.progress_summary,
+ (SELECT COUNT(*) FROM tasks WHERE parent_task_id = t.id) as subtask_count,
+ t.version, t.is_supervisor, COALESCE(t.hidden, false) as hidden, t.created_at, t.updated_at
+ FROM tasks t
+ LEFT JOIN contracts c ON t.contract_id = c.id
+ WHERE t.owner_id = $1
+ AND t.directive_id = $2
+ AND t.directive_step_id IS NULL
+ AND t.parent_task_id IS NULL
+ AND COALESCE(t.hidden, false) = false
+ ORDER BY t.created_at DESC
+ "#,
+ )
+ .bind(owner_id)
+ .bind(directive_id)
+ .fetch_all(pool)
+ .await
+}
+
+/// List "orphan" top-level tasks for an owner — tasks that are NOT attached
+/// to a directive and NOT a subtask of another task. These surface in the
+/// document-mode sidebar under a top-level `tmp/` folder. Hidden tasks
+/// excluded.
+pub async fn list_orphan_tasks_for_owner(
+ pool: &PgPool,
+ owner_id: Uuid,
+) -> Result<Vec<TaskSummary>, sqlx::Error> {
+ sqlx::query_as::<_, TaskSummary>(
+ r#"
+ SELECT
+ t.id, t.contract_id, c.name as contract_name, c.phase as contract_phase,
+ c.status as contract_status,
+ t.parent_task_id, t.depth, t.name, t.status, t.priority,
+ t.progress_summary,
+ (SELECT COUNT(*) FROM tasks WHERE parent_task_id = t.id) as subtask_count,
+ t.version, t.is_supervisor, COALESCE(t.hidden, false) as hidden, t.created_at, t.updated_at
+ FROM tasks t
+ LEFT JOIN contracts c ON t.contract_id = c.id
+ WHERE t.owner_id = $1
+ AND t.parent_task_id IS NULL
+ AND t.directive_id IS NULL
+ AND COALESCE(t.hidden, false) = false
+ ORDER BY t.priority DESC, t.created_at DESC
+ "#,
+ )
+ .bind(owner_id)
+ .fetch_all(pool)
+ .await
+}
+
/// List subtasks of a parent task, scoped to owner.
pub async fn list_subtasks_for_owner(
pool: &PgPool,