Skip to content
Snippets Groups Projects
Commit 5b09f53f authored by elit04's avatar elit04
Browse files

modifications on boat routes/controllers

parent a174c0d3
No related branches found
No related tags found
No related merge requests found
...@@ -20,8 +20,20 @@ const createBoat = async (req: Request, res: Response) => { ...@@ -20,8 +20,20 @@ const createBoat = async (req: Request, res: Response) => {
.status(404) .status(404)
.json({ success: false, error: "boattypeNotFound" }); .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) { if (newBoat) {
return res.status(201).json({ return res.status(201).json({
success: true, success: true,
...@@ -35,17 +47,6 @@ const createBoat = async (req: Request, res: Response) => { ...@@ -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) { } catch (error) {
console.error(error.message); console.error(error.message);
return res.status(500).json({ success: false, error: "serverError" }); return res.status(500).json({ success: false, error: "serverError" });
......
...@@ -26,6 +26,8 @@ boatsRouter.post( ...@@ -26,6 +26,8 @@ boatsRouter.post(
body("boattype").not().isEmpty(), body("boattype").not().isEmpty(),
body("status").not().isEmpty() && body("status").isIn([1, 0]), body("status").not().isEmpty() && body("status").isIn([1, 0]),
body("tags").if(body("tags").exists()).isArray(), //optional tags field body("tags").if(body("tags").exists()).isArray(), //optional tags field
body("minP").isInt(),
body("maxP").isInt(),
handleValidationResult, handleValidationResult,
validateToken, validateToken,
boatControllers.createBoat boatControllers.createBoat
...@@ -38,6 +40,8 @@ boatsRouter.patch( ...@@ -38,6 +40,8 @@ boatsRouter.patch(
body("boattype").if(body("boattype").exists()).not().isEmpty(), body("boattype").if(body("boattype").exists()).not().isEmpty(),
body("status").if(body("status").exists()).not().isEmpty().isIn([1, 0]), body("status").if(body("status").exists()).not().isEmpty().isIn([1, 0]),
body("tags").if(body("tags").exists()).isArray(), body("tags").if(body("tags").exists()).isArray(),
body("minP").if(body("minP").exists()).isInt(),
body("maxP").if(body("maxP").exists()).isInt(),
handleValidationResult, handleValidationResult,
validateToken, validateToken,
boatControllers.updateBoatById boatControllers.updateBoatById
......
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