From e3e1b2dc14d62e798d280355dae97df151a4de7f Mon Sep 17 00:00:00 2001 From: chamikaJ Date: Mon, 9 Jun 2025 13:05:34 +0530 Subject: [PATCH] fix(tasks-controller): cap progress calculation at 100% and synchronize complete_ratio - Updated progress calculation to ensure it does not exceed 100% when time-based progress is enabled. - Set complete_ratio to match the calculated progress, improving accuracy in task completion representation. - Simplified comments for clarity regarding progress defaults and calculations. --- .../src/controllers/tasks-controller-base.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/worklenz-backend/src/controllers/tasks-controller-base.ts b/worklenz-backend/src/controllers/tasks-controller-base.ts index abb074d5..bc038dec 100644 --- a/worklenz-backend/src/controllers/tasks-controller-base.ts +++ b/worklenz-backend/src/controllers/tasks-controller-base.ts @@ -52,15 +52,17 @@ export default class TasksControllerBase extends WorklenzControllerBase { } // For tasks with no subtasks and no manual progress else { - // Only calculate time-based progress if time-based calculation is enabled for the project + // Only calculate progress based on time if time-based progress is enabled for the project if (task.project_use_time_progress && task.total_minutes_spent && task.total_minutes) { - task.progress = ~~(task.total_minutes_spent / task.total_minutes * 100); - task.complete_ratio = task.progress; + // Cap the progress at 100% to prevent showing more than 100% progress + task.progress = Math.min(~~(task.total_minutes_spent / task.total_minutes * 100), 100); } else { - // Default to 0% progress for incomplete tasks when time-based calculation is not enabled + // Default to 0% progress when time-based calculation is not enabled task.progress = 0; - task.complete_ratio = 0; } + + // Set complete_ratio to match progress + task.complete_ratio = task.progress; } // Ensure numeric values