diff --git a/server/src/controllers/boat.controllers.ts b/server/src/controllers/boat.controllers.ts index 6ec80f751cf5e2708decdd4a913574ebb044cfcc..ed78a21924baa3e75fb527de1fe2170919ad483c 100644 --- a/server/src/controllers/boat.controllers.ts +++ b/server/src/controllers/boat.controllers.ts @@ -20,8 +20,20 @@ const createBoat = async (req: Request, res: Response) => { .status(404) .json({ success: false, error: "boattypeNotFound" }); } - const newBoat = await Boat.create(newBoatInput); + const newBoat = await Boat.create(newBoatInput); + + //nachdem das Boot erstellt wurde: + //boatTypeTabelle: boattype-id + //beim Erstellen von neuem Boot + //boatTypeId: eingabe + const boattypeid = boatType.id; + const boatid = newBoat.id; + const entry = { boatid, boattypeid }; + + //create new entry in boatHasBoatType + await BoatHasBoatType.create(entry); + if (newBoat) { return res.status(201).json({ success: true, @@ -35,17 +47,6 @@ const createBoat = async (req: Request, res: Response) => { }, }); } - - //nachdem das Boot erstellt wurde: - //boatTypeTabelle: boattype-id - //beim Erstellen von neuem Boot - //boatTypeId: eingabe - - const boattypeid = newBoatInput.boatTypeId; - const boatid = newBoat.id; - const entry = { boattypeid, boatid }; - //create new entry in boatHasBoatType - await BoatHasBoatType.create(entry); } catch (error) { console.error(error.message); return res.status(500).json({ success: false, error: "serverError" }); diff --git a/server/src/routes/boat.routes.ts b/server/src/routes/boat.routes.ts index c8606c3757844219819f04e79a40fd6394367781..f123d3410970df616cf30881fb36bcfe4b5e7006 100644 --- a/server/src/routes/boat.routes.ts +++ b/server/src/routes/boat.routes.ts @@ -26,6 +26,8 @@ boatsRouter.post( body("boattype").not().isEmpty(), body("status").not().isEmpty() && body("status").isIn([1, 0]), body("tags").if(body("tags").exists()).isArray(), //optional tags field + body("minP").isInt(), + body("maxP").isInt(), handleValidationResult, validateToken, boatControllers.createBoat @@ -38,6 +40,8 @@ boatsRouter.patch( body("boattype").if(body("boattype").exists()).not().isEmpty(), body("status").if(body("status").exists()).not().isEmpty().isIn([1, 0]), body("tags").if(body("tags").exists()).isArray(), + body("minP").if(body("minP").exists()).isInt(), + body("maxP").if(body("maxP").exists()).isInt(), handleValidationResult, validateToken, boatControllers.updateBoatById