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.
This commit is contained in:
shancds
2025-07-01 10:18:56 +05:30
parent c048085c8a
commit e5ff036d81

View File

@@ -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);