this is the front end code to update the progress which being send by using this function,only the first console log line getting console nothing else
const handleSaveProgress = async () => {
console.log('handleSaveProgress called');
if (selectedTaskIndex !== null && selectedTaskIndex >= 0 && selectedTaskIndex <
updatedTasks.length) {
const updatedTask = updatedTasks[selectedTaskIndex];
const { progress: updatedProgress, _id } = updatedTask;
console.log(`Saving progress for task ID ${_id} with progress ${updatedProgress}`);
try {
const backendPort = import.meta.env.VITE_BACKEND_PORT || 'http://localhost:3000';
console.log(`Sending PATCH request to ${backendPort}/tasks/${_id}/progress?
`progress=${updatedProgress});`
const response = await axios.patch(`${backendPort}/tasks/${_id}/progress`, null, {
params: {
progress: updatedProgress,
},
});
console.log("Response status:", response.status);
console.log("Response data:", response.data);
if (response.status === 200) {
console.log('Progress updated successfully:', response.data);
setUpdatedTasks((prevTasks) => {
const newTasks = [...prevTasks];
newTasks[selectedTaskIndex] = {
...newTasks[selectedTaskIndex],
progress: updatedProgress,
};
return newTasks;
});
setShowModal(false); // Close modal on success
} else {
console.error('Failed to update progress:', response.data);
}
} catch (error) {
console.error('Error updating progress:', error);
}
}
};
on sending this “http://localhost:5000/tasks/663c5474dbeffd71e2a501e2/progress?progress=80” request on postman, the backend is getting updated
the backend code is:
app.patch("/tasks/:id/progress",async(req,res)=>{
try{
const taskId = req.params.id;
const progress = req.query.progress;
console.log("Received progress:", progress);;
if (!progress || isNaN(progress) || progress < 0 || progress > 100) {
return res.status(400).json({ message: "Progress must be a number between 0 and 100" });
}
console.log("Received progress:", progress);
let status="Pending";
if(progress>0 && progress<100)
{ status="InProgress";}
else if(progress==100)
{ status="Completed";}
const updatedTask=await Task.findByIdAndUpdate(taskId,{status,progress},{new:true});
if(!updatedTask)
{
return res.status(404).json({message:"task not found"});
}
res.json({message:"Task Updated Successfully",task:updatedTask});
}
catch(error)
{
return res.status(500).json({error:error.message});
}
});
New contributor
Kunjal singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.