Skip to content

Commit

Permalink
#update functionality admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
SwayamRana808 committed May 19, 2024
1 parent dcb03a7 commit 1431efc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions backend/app/routes/admin/updateAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ module.exports =async (req, res) => {
if (admin.image && admin.image!=="undefined" && req.file?.path) {
fs.unlinkSync(path.join(__dirname,'..' ,'..','..', admin.image));
}

try {
let updateFields = { ...req.body };
let updateFields = {
firstName:req.body.firstName,
lastName:req.body.lastName,
contact:req.body.contact,
username:req.body.username
};
if (req.file?.path) {
updateFields.image = req.file.path;
}else{
updateFields.image = admin.image;
}

const updatedAdmin = await Admin.findByIdAndUpdate(
req.params.id,
{ $set: updateFields },
{ new: true }
);

res.status(200).json(updatedAdmin);
res.status(200).json({updatedAdmin,updateFields});
} catch (err) {
res.status(500).json(err);
}
Expand Down

0 comments on commit 1431efc

Please sign in to comment.