(req, res)
| 293 | |
| 294 | // Update user |
| 295 | const 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 |
| 328 | const deleteUser = async (req, res) => { |
nothing calls this directly
no outgoing calls
no test coverage detected