From ffeeb9aa9792f32061e818d3ac32b51d25f31c52 Mon Sep 17 00:00:00 2001 From: elit04 <elit04@fu-berlin.de> Date: Sun, 23 Jan 2022 09:58:12 -0500 Subject: [PATCH] working update boat controller --- server/src/controllers/boat.controllers.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/server/src/controllers/boat.controllers.ts b/server/src/controllers/boat.controllers.ts index 1390153..0106367 100644 --- a/server/src/controllers/boat.controllers.ts +++ b/server/src/controllers/boat.controllers.ts @@ -51,7 +51,6 @@ const createBoat = async (req: Request, res: Response) => { //if there is a sport, which isn't in the database, we return an array with the names of the missing sports if (check === false) { - console.log("list", listIfNotFound); return res.status(404).json({ success: false, error: "The SportIDs: " + listIfNotFound + " cannotBeFound", @@ -265,7 +264,6 @@ const updateBoatById = async (req: Request, res: Response) => { //if the updated-to-be sportid(sportids) doesn't exist if (check === false) { - console.log("list", listIfNotFound); return res .status(404) .json({ success: false, error: listIfNotFound + " sportIdNotFound" }); @@ -295,7 +293,8 @@ const updateBoatById = async (req: Request, res: Response) => { }); //we need this special case res, because sports is not an attribute assigned to Boat table, and if only sports provided as request body error happens - if (updatedBoat === undefined) { + // check if in the requested body only values for sports were provided + if (Object.keys(input).length === 1 && !(input.sports === undefined)) { //return after updating return res.status(200).json({ success: true, @@ -314,7 +313,6 @@ const updateBoatById = async (req: Request, res: Response) => { //case where in request body attributes from Boat provided + sports which is an attribute in Sport table and connection between Boat and Sport is saved in BoatHasSport table const boatDataAfterUpdate = updatedBoat[1][0]; - console.log("boatDataAfterUpdate ", boatDataAfterUpdate); return res.status(200).json({ success: true, result: { -- GitLab