diff --git a/server/src/controllers/accounts.controllers.ts b/server/src/controllers/accounts.controllers.ts index b2f7772b4954ed6eadc98072c605587a5041182e..6c3b8d3848294265941eb59f169398c426fcec26 100644 --- a/server/src/controllers/accounts.controllers.ts +++ b/server/src/controllers/accounts.controllers.ts @@ -119,6 +119,15 @@ const updateAccount = async (req: Request, res: Response) => { //take what ever in req.body is, and pass it to update() const input = req.body; + + //return 200 with empty response if no data was given + if (Object.keys(input).length === 0) { + return res + .status(200) + .json({ success: true, result: {}, message: "noInputFound" }); + } + + //get given id const givenId = req.params.id; //check if given ID exists in DB diff --git a/server/src/controllers/boatControllers.controllers.ts b/server/src/controllers/boatControllers.controllers.ts index bc3f21bcca2a2a4f3987118a6fd55ccb86c6d9e8..5c4567bd8571d8dfd98e0362cac3859affbef4ac 100644 --- a/server/src/controllers/boatControllers.controllers.ts +++ b/server/src/controllers/boatControllers.controllers.ts @@ -120,6 +120,16 @@ const updateBoatById = async (req: Request, res: Response) => { .json({ success: false, error: "MustBeCoordinator" }); } + //get new input + const input = req.body; + + //return 200 with empty response if no data was given + if (Object.keys(input).length === 0) { + return res + .status(200) + .json({ success: true, result: {}, message: "noInputFound" }); + } + //get id const givenId = req.params.id; @@ -130,9 +140,6 @@ const updateBoatById = async (req: Request, res: Response) => { return res.status(404).json({ success: false, error: "boatIdNotFound" }); } - //get new input - const input = req.body; - //try to update const updatedBoat = await Boat.update(input, { where: { diff --git a/server/src/controllers/boatTypeControllers.controllers.ts b/server/src/controllers/boatTypeControllers.controllers.ts index 37f6aa2faf545c6395b8e1f975e9dd846a05c7b4..5b207fae3ed3089d2a825afaf78479bfeb799825 100644 --- a/server/src/controllers/boatTypeControllers.controllers.ts +++ b/server/src/controllers/boatTypeControllers.controllers.ts @@ -112,6 +112,16 @@ const updateBoatTypeById = async (req: Request, res: Response) => { .json({ success: false, error: "MustBeCoordinator" }); } + //get new input + const input = req.body; + + //return 200 with empty response if no data was given + if (Object.keys(input).length === 0) { + return res + .status(200) + .json({ success: true, result: {}, message: "noInputFound" }); + } + //get id const givenId = req.params.id; @@ -124,9 +134,6 @@ const updateBoatTypeById = async (req: Request, res: Response) => { .json({ success: false, error: "boatTypeIdNotFound" }); } - //get new input - const input = req.body; - //try to update const updatedBoatType = await BoatType.update(input, { where: { diff --git a/server/src/controllers/userControllers.controllers.ts b/server/src/controllers/userControllers.controllers.ts index 5052179050ea81d4cc79899823bc8520796f02a1..cea32377fb6cab1ec1ea0f21505e0a1807d3fc82 100644 --- a/server/src/controllers/userControllers.controllers.ts +++ b/server/src/controllers/userControllers.controllers.ts @@ -12,18 +12,16 @@ const showCurrentUserController = async (req: Request, res: Response) => { }, }); - res - .status(200) - .json({ - success: true, - result: { - id: currentUserData.id, - first_name: currentUserData.first_name, - last_name: currentUserData.last_name, - email: currentUserData.email, - role: currentUserData.role, - }, - }); + res.status(200).json({ + success: true, + result: { + id: currentUserData.id, + first_name: currentUserData.first_name, + last_name: currentUserData.last_name, + email: currentUserData.email, + role: currentUserData.role, + }, + }); } catch (error) { console.log("server error: ", error.message); res.status(500).json({ success: false, error: "serverError!" }); @@ -43,6 +41,13 @@ const updateCurrentUser = async (req: Request, res: Response) => { //take what ever in req.body is, and pass it to update() const input = req.body; //Data are saved in the DB in camelCase + //return 200 with empty response if no data was given + if (Object.keys(input).length === 0) { + return res + .status(200) + .json({ success: true, result: {}, message: "noInputFound" }); + } + if (input.password !== undefined) { input.password = await bcrypt.hash(input.password, 10); } @@ -61,7 +66,16 @@ const updateCurrentUser = async (req: Request, res: Response) => { const updatedEmployee = EmployeeDataAfterUpdate[1][0]; delete updatedEmployee.password; - return res.status(200).json({ success: true, result: updatedEmployee }); + return res.status(200).json({ + success: true, + result: { + id: updatedEmployee.id, + first_name: updatedEmployee.first_name, + last_name: updatedEmployee.last_name, + email: updatedEmployee.email, + role: updatedEmployee.role, + }, + }); } catch (error) { console.error("server error: ", error.message); return res.status(500).json({ success: false, error: "serverError" });