Skip to content

Commit

Permalink
creation of route for updating administrator registration with authen…
Browse files Browse the repository at this point in the history
…tication
  • Loading branch information
Priscila Estevao da Cunha committed Dec 10, 2020
1 parent b9ecf4c commit 562f2be
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/controllers/adminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const registerNewAdmin = (req, res) => {
const token = auth(req, res);
jwt.verify(token, SECRET, (err) => {
if (err) {
return res.status(403).send("Invalid token!")
return res.status(403).send("Invalid token!");
}
const encryptedPassword = bcrypt.hashSync(req.body.password, 10);
req.body.password = encryptedPassword;
Expand Down Expand Up @@ -62,7 +62,22 @@ const login = (req, res) => {
};

const updateAdministrator = (req, res) => {

const token = auth(req, res);
jwt.verify(token, SECRET, (err) => {
if (err) {
return res.status(403).send("Invalid token!");
}
const id = req.params.id;
const updateAdmin = req.body;
adminModel.findByIdAndUpdate(id, updateAdmin, (err, admin) => {
if (err) {
return res.status(424).send({ message: err.message });
} else if (admin) {
return res.status(200).send("Administrator update successfully!");
}
res.status(404).send("Administrator not found!");
});
});
};

const deleteAdministrator = (req, res) => {};
Expand Down

0 comments on commit 562f2be

Please sign in to comment.