Skip to content

Commit

Permalink
controller and index/server updates
Browse files Browse the repository at this point in the history
  • Loading branch information
txingxie committed Nov 21, 2024
1 parent 5a4a155 commit 57e95f9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
12 changes: 6 additions & 6 deletions api/src/controllers/mentorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ 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<void> => {
try {
const { mentorId } = req.params;

// Find the mentor, populate mentees, and include mentee workshops
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 });
}
};
14 changes: 13 additions & 1 deletion api/src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -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 };
Expand Down
4 changes: 4 additions & 0 deletions api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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}`),
);

0 comments on commit 57e95f9

Please sign in to comment.