From e5ff036d811755f90ef6de9bae670ce09655566d Mon Sep 17 00:00:00 2001 From: shancds Date: Tue, 1 Jul 2025 10:18:56 +0530 Subject: [PATCH] feat(task-status): enhance task status change handling to reset manual progress - Added logic to reset manual_progress to FALSE when a task transitions from "done" to "todo" or "doing", allowing for accurate progress recalculation based on subtasks. - Improved logging for task status changes to provide better insights into task management actions. - Ensured parent task progress updates are triggered appropriately for subtasks during status changes. --- .../commands/on-task-status-change.ts | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/worklenz-backend/src/socket.io/commands/on-task-status-change.ts b/worklenz-backend/src/socket.io/commands/on-task-status-change.ts index 0d003b59..e59e6b59 100644 --- a/worklenz-backend/src/socket.io/commands/on-task-status-change.ts +++ b/worklenz-backend/src/socket.io/commands/on-task-status-change.ts @@ -58,10 +58,10 @@ export async function on_task_status_change(_io: Server, socket: Socket, data?: FROM tasks WHERE id = $1 `, [body.task_id]); - + const currentProgress = progressResult.rows[0]?.progress_value; const isManualProgress = progressResult.rows[0]?.manual_progress; - + // Only update if not already 100% if (currentProgress !== 100) { // Update progress to 100% @@ -70,9 +70,9 @@ export async function on_task_status_change(_io: Server, socket: Socket, data?: SET progress_value = 100, manual_progress = TRUE WHERE id = $1 `, [body.task_id]); - + log(`Task ${body.task_id} moved to done status - progress automatically set to 100%`, null); - + // Log the progress change to activity logs await logProgressChange({ task_id: body.task_id, @@ -80,7 +80,7 @@ export async function on_task_status_change(_io: Server, socket: Socket, data?: new_value: "100", socket }); - + // If this is a subtask, update parent task progress if (body.parent_task) { setTimeout(() => { @@ -88,6 +88,23 @@ export async function on_task_status_change(_io: Server, socket: Socket, data?: }, 100); } } + } else { + // Task is moving from "done" to "todo" or "doing" - reset manual_progress to FALSE + // so progress can be recalculated based on subtasks + await db.query(` + UPDATE tasks + SET manual_progress = FALSE + WHERE id = $1 + `, [body.task_id]); + + log(`Task ${body.task_id} moved from done status - manual_progress reset to FALSE`, null); + + // If this is a subtask, update parent task progress + if (body.parent_task) { + setTimeout(() => { + socket.emit(SocketEvents.GET_TASK_PROGRESS.toString(), body.parent_task); + }, 100); + } } const info = await TasksControllerV2.getTaskCompleteRatio(body.parent_task || body.task_id);