//another check if sports array was provided and it's with valid sport ids => create entry in BoatHasSport table with the new created boat id and corresponding sport is
if (!(sportsArray==undefined)){
if (listIfFound.length===sportsArray.length){
constboatid=newBoat.id;
//create entry (boatid, each id of given sportIds)
for (leti=0;i<sportsArray.length;i++){
constsportid=sportsArray[i];
constentry={boatid,sportid};
//create new entry in boatHasBoatType
awaitBoatHasSport.create(entry);
//create entry (boatid, each id of given sportIds)
//first we need to destroy entries where the to-be-deleted boat is connected with sport in BoatHasSport table, because it violates the foreign constraint
//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)){
//return after updating
returnres.status(200).json({
success:true,
result:{
id:givenId,
name:findBoatInfo.name,
boattype:findBoatInfo.boattype,
status:findBoatInfo.status,
tags:findBoatInfo.tags,
minP:findBoatInfo.minP,
maxP:findBoatInfo.maxP,
sports:listOfNames,
},
});
}
//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