Skip to content
Snippets Groups Projects
Commit 6379c946 authored by elit04's avatar elit04
Browse files

modified sport controller

parent 382b9695
No related branches found
No related tags found
No related merge requests found
...@@ -73,7 +73,7 @@ const deleteSportById = async (req: Request, res: Response) => { ...@@ -73,7 +73,7 @@ const deleteSportById = async (req: Request, res: Response) => {
//delete using given id //delete using given id
const givenId = req.params.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( await BoatHasSport.destroy(
{ {
where: { where: {
...@@ -101,7 +101,7 @@ const deleteSportById = async (req: Request, res: Response) => { ...@@ -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) => { const updateSportById = async (req: Request, res: Response) => {
try { try {
//check authority //check authority
...@@ -180,14 +180,17 @@ const showSportByBoatId = async (req: Request, res: Response) => { ...@@ -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++) { for (let i =0; i < findAllBoatId.length; i++) {
const found = await Sport.findByPk(findAllBoatId[i].sportid) const found = await Sport.findByPk(findAllBoatId[i].sportid)
return res list.push(found.name)
.status(200)
.json({ success: true, result: { sport: 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" }); return res.status(404).json({ success: false, error: "boatIdNotFound" });
} catch (error) { } catch (error) {
console.error("server error: ", error.message); console.error("server error: ", error.message);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment