diff --git a/api/src/controllers/mentorController.ts b/api/src/controllers/mentorController.ts index d2a9421..ee77fd1 100644 --- a/api/src/controllers/mentorController.ts +++ b/api/src/controllers/mentorController.ts @@ -2,7 +2,7 @@ import { Request, Response } from "express"; import { Mentor } from "../model/Mentor"; // Get all mentees and their workshops for a given mentor -export const getMenteesForMentor = async (req: Request, res: Response) => { +export const getMenteesForMentor = async (req: Request, res: Response): Promise => { try { const { mentorId } = req.params; @@ -10,20 +10,20 @@ export const getMenteesForMentor = async (req: Request, res: Response) => { const mentor = await Mentor.findById(mentorId) .populate({ path: "mentees", - populate: { path: "workshops" }, // Include workshops for each mentee + populate: { path: "workshops" }, // workshops for each mentee }) - .populate("workshops"); // Include workshops for the mentor + .populate("workshops"); // workshops for the mentor if (!mentor) { - return res.status(404).json({ message: "Mentor not found" }); + return; } - return res.status(200).json({ + res.status(200).json({ mentees: mentor.mentees, workshops: mentor.workshops, }); } catch (error) { console.error(error); - return res.status(500).json({ message: "An error occurred", error }); + res.status(500).json({ message: "An error occurred", error }); } }; diff --git a/api/src/routes/index.ts b/api/src/routes/index.ts index 4bf9a11..2f4f2d5 100644 --- a/api/src/routes/index.ts +++ b/api/src/routes/index.ts @@ -1,6 +1,18 @@ import user from "./user"; import express from "express"; -import workshop from "./workshop"; // Import workshop routes +import workshop from "./workshop"; // workshop routes +import mentor from "./mentor"; // mentor routes +import mentee from "./mentee"; // mentee routes + +const router = express.Router(); + +// Route definitions +router.use("/user", user); +router.use("/workshop", workshop); +router.use("/mentor", mentor); +router.use("/mentee", mentee); + +export default router; // export { workshops } export { user, workshop }; diff --git a/api/src/server.ts b/api/src/server.ts index c3f6ace..60a1b30 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -5,6 +5,7 @@ import express from "express"; import bodyParser from "body-parser"; import connectDB from "./config/db"; import * as routes from "./routes/index"; +import router from "./routes"; import path from "path"; var cors = require("cors"); @@ -19,6 +20,9 @@ app.use("/workshop", routes.workshop); connectDB(); + +app.use("/api", router); // connect routes (prefix as api), what is the lin 7 logic for?: import * as routes from "./routes/index" + app.listen(process.env.PORT || 8000, () => console.log(`Server running on port ${process.env.PORT || 8000}`), );