Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
boat.routes.ts 1.45 KiB
import { Router } from "express";
import { body } from "express-validator";
import validateToken from "../middleware/validateToken";
import boatControllers from "../controllers/boat.controllers";
import handleValidationResult from "../middleware/handleValidationResult";

const boatsRouter = Router();

//show all boats
boatsRouter.get("/api/boat/", boatControllers.showAllBoatsController);

//show boat by given id
boatsRouter.get("/api/boat/:id", boatControllers.showBoatById);

//delete a boat
boatsRouter.delete(
  "/api/boat/:id",
  validateToken,
  boatControllers.deleteBoatById
);

//create boat
boatsRouter.post(
  "/api/boat/",
  body("name").not().isEmpty(),
  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
);

//update boat by id
boatsRouter.patch(
  "/api/boat/:id/",
  body("name").if(body("name").exists()).not().isEmpty(),
  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
)


export default boatsRouter;