Refactor task progress update logic in socket command

- Improved error logging for manual progress updates on parent tasks.
- Cleaned up console log statements and replaced them with a logging function for consistency.
- Fixed SQL query to remove unnecessary team_id selection, streamlining the data retrieval process.
This commit is contained in:
chamiakJ
2025-04-30 15:47:28 +05:30
parent 6128c64c31
commit 0c5eff7121

View File

@@ -11,13 +11,9 @@ interface UpdateTaskProgressData {
} }
export async function on_update_task_progress(io: any, socket: Socket, data: string) { export async function on_update_task_progress(io: any, socket: Socket, data: string) {
try { try {
log(socket.id, `${SocketEvents.UPDATE_TASK_PROGRESS}: ${data}`);
const parsedData = JSON.parse(data) as UpdateTaskProgressData; const parsedData = JSON.parse(data) as UpdateTaskProgressData;
const { task_id, progress_value, parent_task_id } = parsedData; const { task_id, progress_value, parent_task_id } = parsedData;
console.log(`Updating progress for task ${task_id}: new value = ${progress_value}`);
if (!task_id || progress_value === undefined) { if (!task_id || progress_value === undefined) {
return; return;
@@ -33,22 +29,19 @@ export async function on_update_task_progress(io: any, socket: Socket, data: str
// If this is a parent task, we shouldn't set manual progress // If this is a parent task, we shouldn't set manual progress
if (subtaskCount > 0) { if (subtaskCount > 0) {
console.log(`Cannot set manual progress on parent task ${task_id} with ${subtaskCount} subtasks`); log_error(`Cannot set manual progress on parent task ${task_id} with ${subtaskCount} subtasks`);
return; return;
} }
// Get the current progress value to log the change // Get the current progress value to log the change
const currentProgressResult = await db.query( const currentProgressResult = await db.query(
"SELECT progress_value, project_id, team_id FROM tasks WHERE id = $1", "SELECT progress_value, project_id, FROM tasks WHERE id = $1",
[task_id] [task_id]
); );
const currentProgress = currentProgressResult.rows[0]?.progress_value; const currentProgress = currentProgressResult.rows[0]?.progress_value;
const projectId = currentProgressResult.rows[0]?.project_id; const projectId = currentProgressResult.rows[0]?.project_id;
const teamId = currentProgressResult.rows[0]?.team_id;
console.log(`Previous progress for task ${task_id}: ${currentProgress}; New: ${progress_value}`);
// Update the task progress in the database // Update the task progress in the database
await db.query( await db.query(
`UPDATE tasks `UPDATE tasks