MCPcopy Create free account
hub / github.com/Muhammadsiddiq-code/backend-group-lessons / updateUser

Function updateUser

controller/userController.js:295–325  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

293
294// Update user
295const updateUser = async (req, res) => {
296 try {
297 const { id } = req.params;
298 const { username, lastname, phone, address } = req.body;
299
300 const updatedUser = await User.findByIdAndUpdate(
301 id,
302 { username, lastname, phone, address },
303 { new: true }
304 );
305
306 if (!updatedUser) {
307 return res.status(404).json({
308 success: false,
309 message: "User not found!",
310 });
311 }
312
313 res.json({
314 success: true,
315 message: "User updated successfully!",
316 user: updatedUser,
317 });
318 } catch (error) {
319 res.status(500).json({
320 success: false,
321 message: "Internal Server Error",
322 error: error.message,
323 });
324 }
325};
326
327// Delete user
328const deleteUser = async (req, res) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected