diff --git a/server/src/controllers/boatTypeControllers.controllers.ts b/server/src/controllers/boatTypeControllers.controllers.ts new file mode 100644 index 0000000000000000000000000000000000000000..8eedb09581314dc44ded24bd9e78302464768ccf --- /dev/null +++ b/server/src/controllers/boatTypeControllers.controllers.ts @@ -0,0 +1,18 @@ +import { Request, Response } from "express"; +import Boat from "../db/models/Boat"; + +//show all BoatTypes(in wiki the name and the seats are returned, but maybe we need the new added boatType attribute??) +const showAllBoatTypes = async (req: Request, res: Response) => { + try { + if (!(res.locals.user.role === "coordinator")) { + return res + .status(403) + .json({ success: false, error: "MustBeCoordinator" }); + } + const allBoatTypes = await Boat.findAll({attributes: ['name', 'seats']}); + return res.status(200).send({ success: true, result: allBoatTypes }); + } catch (error) { + console.error("server error: ", error.message); + return res.status(500).json({ success: false, error: "serverError" }); + } + }; \ No newline at end of file diff --git a/server/src/routes/boatTypeRoutes.routes.ts b/server/src/routes/boatTypeRoutes.routes.ts new file mode 100644 index 0000000000000000000000000000000000000000..1b582df135f770d55646cfde9ffe93f0acea792a --- /dev/null +++ b/server/src/routes/boatTypeRoutes.routes.ts @@ -0,0 +1,16 @@ +import { Router } from "express"; +import { body } from "express-validator"; +import boatTypeControllers from "../controllers/boatTypeControllers.controllers"; +import handleValidationResult from "../middleware/handleValidationResult"; +import validateToken from "../middleware/validateToken"; + +const boatTypeRouter = Router(); + +//show all boatTypes +boatTypeRouter.get( + "/api/boattype/", + validateToken, + boatTypeControllers.showAllBoatTypes +); + +export default boatTypeRouter; \ No newline at end of file diff --git a/server/src/server.ts b/server/src/server.ts index f8e7e2b3828285e0edb62e6e1c54674195a8d22f..0095cd1c9d53a25577f24d6cac8dc8491e3c480d 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -11,6 +11,7 @@ import accountsRouter from "./routes/accounts.routes"; import authRouter from "./routes/auth.routes"; import boatsRouter from "./routes/boatRoutes.routes"; import userRouter from "./routes/user.routes"; +import boatTypeRouter from "./routes/boatTypeRoutes.routes"; let init = async () => { //DB @@ -28,6 +29,7 @@ let init = async () => { app.use("/", accountsRouter); app.use("/", boatsRouter); app.use("/", userRouter); + app.use("/", boatTypeRouter); //DB-information section await showAllDBs(sequelize); await showTables(sequelize);