diff --git a/server/src/controllers/accounts.controllers.ts b/server/src/controllers/accounts.controllers.ts index 451169224c7d0f5fba6e1aace0383a34b8a30d42..4d8f1651f397c7ab82d51a504161fcfdf9194371 100644 --- a/server/src/controllers/accounts.controllers.ts +++ b/server/src/controllers/accounts.controllers.ts @@ -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;