-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into trevor/getMenteesEndpoint/39
- Loading branch information
Showing
29 changed files
with
1,181 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,5 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
**/**/.env |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
import { | ||
InvalidTokenError, | ||
UnauthorizedError, | ||
} from "express-oauth2-jwt-bearer"; | ||
|
||
export const errorHandler = ( | ||
error: any, | ||
request: Request, | ||
response: Response, | ||
next: NextFunction, | ||
) => { | ||
console.log("Auth Error"); | ||
|
||
if (error instanceof InvalidTokenError) { | ||
const message = "Bad credentials"; | ||
|
||
response.status(error.status).json({ message }); | ||
|
||
return; | ||
} | ||
|
||
if (error instanceof UnauthorizedError) { | ||
const message = "Requires authentication"; | ||
|
||
response.status(error.status).json({ message }); | ||
|
||
return; | ||
} | ||
|
||
const status = 500; | ||
const message = "Internal Server Error"; | ||
|
||
response.status(status).json({ message }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { auth } from "express-oauth2-jwt-bearer"; | ||
import dotenv from "dotenv"; | ||
import path from "path"; | ||
|
||
dotenv.config({ path: path.resolve(__dirname, "../.env") }); | ||
|
||
const auth0Domain = process.env.AUTH0_DOMAIN; | ||
const auth0Audience = process.env.AUTH0_AUDIENCE; | ||
|
||
try { | ||
if (!auth0Domain || !auth0Audience) { | ||
throw new Error("AUTH0_DOMAIN or AUTH0_AUDIENCE is not set"); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
export const validateAccessToken = auth({ | ||
issuerBaseURL: `https://${auth0Domain}`, | ||
audience: auth0Audience, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
|
||
export const notFoundHandler = ( | ||
request: Request, | ||
response: Response, | ||
next: NextFunction, | ||
) => { | ||
const message = "Not Found"; | ||
|
||
response.status(404).json({ message }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,47 @@ | ||
import express from "express"; | ||
import mongoose from "mongoose"; | ||
import dbConnect from "../config/db"; // Import the dbConnect function | ||
|
||
import { createWorkshop, getWorkshop } from "../controllers/workshopController"; | ||
// import { validateAccessToken } from "../controllers/auth0-middleware"; | ||
|
||
const router = express.Router(); | ||
|
||
// TODO: Add auth0 middleware | ||
// router.use(validateAccessToken); | ||
|
||
// Call the dbConnect function to connect to MongoDB | ||
dbConnect(); | ||
|
||
// Workshop schema definition (name and S3 bucket ID) | ||
const workshopIDSchema = new mongoose.Schema({ | ||
name: String, | ||
s3ID: String, | ||
// Workshop schema definition (name (required by user), description (required by user), and S3 bucket ID (not required as user input)) | ||
const workshopSchema = new mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
description: { type: String, required: true }, | ||
s3id: { type: String, required: false }, | ||
}); | ||
|
||
const Workshop = mongoose.model("WorkshopID", workshopIDSchema); | ||
const Workshop = mongoose.model("Workshop", workshopSchema); | ||
|
||
// Route to create a new workshop | ||
router.post("/create-workshop", async (req: any, res: any) => { | ||
const { name, s3id } = req.body; | ||
const { name, description, s3id } = req.body; | ||
|
||
if (!name || !s3id) { | ||
if (!name || !description) { | ||
return res.status(400).json({ message: "Missing required fields" }); | ||
} | ||
|
||
// Create a new workshop | ||
const newWorkshop = new Workshop({ | ||
name, | ||
s3id, | ||
}); | ||
|
||
try { | ||
// Create a new workshop with | ||
const newWorkshop = new Workshop({ name, description, s3id }); | ||
const savedWorkshop = await newWorkshop.save(); | ||
|
||
// Success: | ||
res.status(201).json({ | ||
message: "Workshop created successfully", | ||
WorkshopID: savedWorkshop, | ||
workshop: savedWorkshop, | ||
}); | ||
} catch (error) { | ||
res.status(401).json({ message: "Failed to create workshop", error }); | ||
console.error("Error saving workshop:", error); | ||
res.status(500).json({ message: "Failed to create workshop", error }); | ||
} | ||
}); | ||
|
||
// router.post("/workshops", createWorkshop) | ||
// router.get('/workshops/:id', getWorkshop); | ||
router.get( | ||
"/workshops/:id", | ||
async (req: express.Request, res: express.Response) => { | ||
await getWorkshop(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; | ||
// NO POPULATE VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.