Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create getWorkshopsByUserId endpoint #15

Merged
merged 6 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions api/src/controllers/workshopController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ export const getWorkshop = async (req: Request, res: Response) => {
}
};

export const getWorkshopsByUserId = async (req: Request, res: Response) => {
try {
const { userId } = req.params;

const workshops = await Workshop.find({
$or: [{ mentor: userId }, { mentee: userId }],
});

if (workshops.length === 0) {
return res
.status(404)
.json({ message: "No workshops found for this user" });
}

res.status(200).json(workshops);
} catch (error) {
res.status(500).json({ message: "Error retrieving workshops", error });
}
};

// POPULATE VERSION (if details of mentor/mentee objects are needed on the frontend like name or picture)

// import { Request, Response } from 'express';
Expand Down
36 changes: 35 additions & 1 deletion api/src/routes/workshop.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import express from "express";
import mongoose from "mongoose";
import dbConnect from "../config/db"; // Import the dbConnect function
// import { validateAccessToken } from "../controllers/auth0-middleware";

import {
createWorkshop,
getWorkshop,
getWorkshopsByUserId,
} from "../controllers/workshopController";

const router = express.Router();

Expand Down Expand Up @@ -44,4 +49,33 @@ router.post("/create-workshop", async (req: any, res: any) => {
}
});

// router.post("/workshops", createWorkshop)
// router.get('/workshops/:id', getWorkshop);
router.get(
"/workshops/:id",
async (req: express.Request, res: express.Response) => {
await getWorkshop(req, res);
},
);

// Route to get workshops by user ID
router.get(
"/workshops/user/:userId",
async (req: express.Request, res: express.Response) => {
await getWorkshopsByUserId(req, res);
},
);

// POPULATE VERSION (if details of mentor/mentee objects are needed on the frontend like name or picture)

// import express from 'express';
// import { createWorkshop, getWorkshop } from '../controllers/workshopController';

// const router = express.Router();

// router.post('/workshops', createWorkshop);
// router.get('/workshops/:id', getWorkshop);

// export default router;

export default router;
Loading