Skip to content
Snippets Groups Projects
Commit 5045b66f authored by elit04's avatar elit04
Browse files

check if given ID exists in DB in uptade account controller

parent 6f368616
No related branches found
No related tags found
No related merge requests found
......@@ -119,6 +119,14 @@ const updateAccount = async (req: Request, res: Response) => {
const input = req.body;
const givenId = req.params.id;
//check if given ID exists in DB
const checkIfIdExists = await Employee.findOne({
attributes: ["id"],
where: {
id: givenId,
},
});
//hash given password
if (input.password !== undefined) {
input.password = await bcrypt.hash(input.password, 10);
......@@ -132,12 +140,6 @@ const updateAccount = async (req: Request, res: Response) => {
returning: true,
});
//Employee not found with given id
//not Working!!!! by giving wrong id -> server error gets thrown
if (userDataAfterUpdate[0] === 0) {
return res.status(404).json({ success: false, error: "accountNotFound" });
}
const userData = userDataAfterUpdate[1][0];
delete userData.password;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment