diff --git a/server/src/controllers/sport.controllers.ts b/server/src/controllers/sport.controllers.ts index 3af89abac94af5b25380ccded27f1e42ac55aca4..ea69981a357a6bc831ea9df7750f4092d0215878 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);