From 6379c94642df7c56ea360db3c21f17863abbac84 Mon Sep 17 00:00:00 2001 From: elit04 <elit04@fu-berlin.de> Date: Fri, 21 Jan 2022 12:48:11 -0500 Subject: [PATCH] modified sport controller --- server/src/controllers/sport.controllers.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/server/src/controllers/sport.controllers.ts b/server/src/controllers/sport.controllers.ts index 3af89ab..ea69981 100644 --- a/server/src/controllers/sport.controllers.ts +++ b/server/src/controllers/sport.controllers.ts @@ -73,7 +73,7 @@ const deleteSportById = async (req: Request, res: Response) => { //delete using given id const givenId = req.params.id; - //first we need to destroy entries where the to-be-deleted sport is assigned to boat in BoatHasSport table, otherwise it violates the foreign key constraint + //first we need to destroy entries where the to-be-deleted sport is assigned to boat in BoatHasSport table, because it violates the foreign constraint await BoatHasSport.destroy( { where: { @@ -101,7 +101,7 @@ const deleteSportById = async (req: Request, res: Response) => { } }; -//update boat by given sport id +//update sport by given sport id const updateSportById = async (req: Request, res: Response) => { try { //check authority @@ -180,14 +180,17 @@ const showSportByBoatId = async (req: Request, res: Response) => { } }); + //define empty array, where we store founded names of sports assigned to boat's id + var list = new Array(); for (let i =0; i < findAllBoatId.length; i++) { const found = await Sport.findByPk(findAllBoatId[i].sportid) - return res - .status(200) - .json({ success: true, result: { sport: found.name } }); - + list.push(found.name) } - } + //return as response the names of the sports + return res + .status(200) + .json({ success: true, result: { sport: list } }); + } return res.status(404).json({ success: false, error: "boatIdNotFound" }); } catch (error) { console.error("server error: ", error.message); -- GitLab