From f892eddcc651ccf8923c3f2f5c07ebd9e5bfd79e Mon Sep 17 00:00:00 2001 From: subha0319 Date: Sun, 2 Nov 2025 16:12:46 +0530 Subject: [PATCH] fix(api): Populate response for updateProject endpoint The PUT /api/projects/:id endpoint returned an unpopulated project object, which was inconsistent with getProjectById. This caused UI bugs on the frontend after an edit. This commit updates the `updateProject` controller to re-fetch, populate (`owner`, `members`), and add the `isOwner` flag to the project object before returning it. This ensures the API response is consistent and resolves the UI bug on the frontend. Fixes #31 --- backend/controllers/projectController.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/controllers/projectController.js b/backend/controllers/projectController.js index 4e177f3..52f05f4 100644 --- a/backend/controllers/projectController.js +++ b/backend/controllers/projectController.js @@ -57,8 +57,17 @@ const updateProject = async (req, res) => { project.description = req.body.description || project.description; project.deadline = req.body.deadline || project.deadline; - const updatedProject = await project.save(); + await project.save(); + + const populatedProject = await Project.findById(project._id) + .populate('owner', 'name email') + .populate('members', 'name email'); + + const updatedProject = populatedProject.toObject(); + updatedProject.isOwner = true; + res.json(updatedProject); + } catch (error) { res.status(500).json({ message: 'Server error while updating project' }); }