From 5b09f53fc1330aa1b8b4ec9189b73ed1da0f3531 Mon Sep 17 00:00:00 2001
From: elit04 <elit04@fu-berlin.de>
Date: Wed, 19 Jan 2022 09:57:13 -0500
Subject: [PATCH] modifications on boat routes/controllers

---
 server/src/controllers/boat.controllers.ts | 25 +++++++++++-----------
 server/src/routes/boat.routes.ts           |  4 ++++
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/server/src/controllers/boat.controllers.ts b/server/src/controllers/boat.controllers.ts
index 6ec80f7..ed78a21 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 c8606c3..f123d34 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
-- 
GitLab