diff --git a/api/src/config/aws.ts b/api/src/config/aws.ts index 4dcdf27..fc6db39 100644 --- a/api/src/config/aws.ts +++ b/api/src/config/aws.ts @@ -1,6 +1,6 @@ -require("dotenv").config(); -const AWS = require("aws-sdk"); -const express = require("express"); +require('dotenv').config(); +const AWS = require('aws-sdk'); +const express = require('express'); const app = express(); // Configure AWS SDK @@ -11,7 +11,7 @@ const s3 = new AWS.S3({ }); // Route to list all files in the S3 bucket -app.get("/files", (req, res) => { +app.get('/files', (req, res) => { const params = { Bucket: process.env.S3_BUCKET_NAME, }; @@ -25,7 +25,7 @@ app.get("/files", (req, res) => { const fileUrls = data.Contents.map((file) => { return { key: file.Key, - url: s3.getSignedUrl("getObject", { + url: s3.getSignedUrl('getObject', { Bucket: process.env.S3_BUCKET_NAME, Key: file.Key, Expires: 60 * 60, // Link expires in 1 hour @@ -39,5 +39,5 @@ app.get("/files", (req, res) => { // Start server app.listen(3001, () => { - console.log("Server started on port 3001"); + console.log('Server started on port 3001'); }); diff --git a/api/src/config/db.ts b/api/src/config/db.ts index 553460f..5c1ed47 100644 --- a/api/src/config/db.ts +++ b/api/src/config/db.ts @@ -1,14 +1,14 @@ -import mongoose from "mongoose"; -import dotenv from "dotenv"; -import path from "path"; +import mongoose from 'mongoose'; +import dotenv from 'dotenv'; +import path from 'path'; -dotenv.config({ path: path.resolve(__dirname, "../../.env") }); +dotenv.config({ path: path.resolve(__dirname, '../../.env') }); // Connect to MongoDB const dbConnect = async () => { try { await mongoose.connect(process.env.MONGO_URI as string, {}); - console.log("Connected to MongoDB"); + console.log('Connected to MongoDB'); } catch (error) { console.error(error); } diff --git a/api/src/controllers/workshopController.ts b/api/src/controllers/workshopController.ts index 8fd36c4..7d9db25 100644 --- a/api/src/controllers/workshopController.ts +++ b/api/src/controllers/workshopController.ts @@ -1,7 +1,7 @@ // NO POPULATE VERSION -import { Request, Response } from "express"; -import { Workshop } from "../model/Workshop"; +import { Request, Response } from 'express'; +import { Workshop } from '../model/Workshop'; export const createWorkshop = async (req: Request, res: Response) => { try { @@ -16,7 +16,7 @@ export const createWorkshop = async (req: Request, res: Response) => { const savedWorkshop = await newWorkshop.save(); res.status(201).json(savedWorkshop); } catch (error) { - res.status(500).json({ message: "Error creating workshop", error }); + res.status(500).json({ message: 'Error creating workshop', error }); } }; @@ -27,12 +27,12 @@ export const getWorkshop = async (req: Request, res: Response) => { const workshop = await Workshop.findById(id); if (!workshop) { - return res.status(404).json({ message: "Workshop not found" }); + return res.status(404).json({ message: 'Workshop not found' }); } res.status(200).json(workshop); } catch (error) { - res.status(500).json({ message: "Error retrieving workshop", error }); + res.status(500).json({ message: 'Error retrieving workshop', error }); } }; diff --git a/api/src/model/Workshop.ts b/api/src/model/Workshop.ts index 20801a1..3f04ada 100644 --- a/api/src/model/Workshop.ts +++ b/api/src/model/Workshop.ts @@ -1,4 +1,4 @@ -import mongoose, { Schema, Document } from "mongoose"; +import mongoose, { Schema, Document } from 'mongoose'; // interface interface IWorkshop extends Document { mentor: Schema.Types.ObjectId; // TODO: add mentor type @@ -11,20 +11,20 @@ interface IWorkshop extends Document { // workshop schema const WorkshopSchema: Schema = new Schema({ - mentor: { type: Schema.Types.ObjectId, ref: "User", required: true }, - mentee: { type: Schema.Types.ObjectId, ref: "User", required: true }, + mentor: { type: Schema.Types.ObjectId, ref: 'User', required: true }, + mentee: { type: Schema.Types.ObjectId, ref: 'User', required: true }, textContent: { type: String, required: true }, createdAt: { type: Date, default: Date.now }, }); // update text content of the workshop WorkshopSchema.methods.updateContent = async function ( - newContent: string + newContent: string, ): Promise { this.textContent = newContent; await this.save(); }; // mongoose model -const Workshop = mongoose.model("Workshop", WorkshopSchema); +const Workshop = mongoose.model('Workshop', WorkshopSchema); export { Workshop, IWorkshop }; diff --git a/api/src/routes/user.ts b/api/src/routes/user.ts index a734b81..416c07a 100644 --- a/api/src/routes/user.ts +++ b/api/src/routes/user.ts @@ -1,6 +1,6 @@ -import express from "express"; -import mongoose from "mongoose"; -import dbConnect from "../config/db"; +import express from 'express'; +import mongoose from 'mongoose'; +import dbConnect from '../config/db'; const router = express.Router(); @@ -13,17 +13,17 @@ const userSchema = new mongoose.Schema({ lastName: String, username: String, email: String, - role: { type: String, enum: ["mentor", "mentee", "admin"], required: true }, + role: { type: String, enum: ['mentor', 'mentee', 'admin'], required: true }, workshopIDs: [String], // For mentors only menteeInfo: [String], // For mentors only meetingSchedule: [String], // For mentees only mentorData: String, // For mentees only }); -const User = mongoose.model("User", userSchema); +const User = mongoose.model('User', userSchema); // Route to create a new user -router.post("/create-user", async (req: any, res: any) => { +router.post('/create-user', async (req: any, res: any) => { const { firstName, lastName, @@ -37,7 +37,7 @@ router.post("/create-user", async (req: any, res: any) => { } = req.body; if (!firstName || !lastName || !username || !email || !role) { - return res.status(400).json({ message: "Missing required fields" }); + return res.status(400).json({ message: 'Missing required fields' }); } // Create a new user based on role @@ -47,25 +47,25 @@ router.post("/create-user", async (req: any, res: any) => { username, email, role, - workshopIDs: role === "mentor" ? workshopIDs : undefined, - menteeInfo: role === "mentor" ? menteeInfo : undefined, - meetingSchedule: role === "mentee" ? meetingSchedule : undefined, - mentorData: role === "mentee" ? mentorData : undefined, + workshopIDs: role === 'mentor' ? workshopIDs : undefined, + menteeInfo: role === 'mentor' ? menteeInfo : undefined, + meetingSchedule: role === 'mentee' ? meetingSchedule : undefined, + mentorData: role === 'mentee' ? mentorData : undefined, }); try { const savedUser = await newUser.save(); res .status(201) - .json({ message: "User created successfully", user: savedUser }); + .json({ message: 'User created successfully', user: savedUser }); } catch (error) { - res.status(400).json({ message: "Failed to create user", error }); + res.status(400).json({ message: 'Failed to create user', error }); } }); // Test route to check if the API is working -router.post("/test", async (req: any, res: any) => { - console.log("Received group data:"); +router.post('/test', async (req: any, res: any) => { + console.log('Received group data:'); const { name } = req.body; return res.status(200).json({ name }); diff --git a/api/src/routes/workshop.ts b/api/src/routes/workshop.ts index 27186ee..c8f3a59 100644 --- a/api/src/routes/workshop.ts +++ b/api/src/routes/workshop.ts @@ -1,8 +1,8 @@ -import express from "express"; -import mongoose from "mongoose"; -import dbConnect from "../config/db"; // Import the dbConnect function +import express from 'express'; +import mongoose from 'mongoose'; +import dbConnect from '../config/db'; // Import the dbConnect function -import { createWorkshop, getWorkshop } from "../controllers/workshopController"; +import { createWorkshop, getWorkshop } from '../controllers/workshopController'; const router = express.Router(); @@ -15,14 +15,14 @@ const workshopIDSchema = new mongoose.Schema({ s3ID: String, }); -const Workshop = mongoose.model("WorkshopID", workshopIDSchema); +const Workshop = mongoose.model('WorkshopID', workshopIDSchema); // Route to create a new workshop -router.post("/create-workshop", async (req: any, res: any) => { +router.post('/create-workshop', async (req: any, res: any) => { const { name, s3id } = req.body; if (!name || !s3id) { - return res.status(400).json({ message: "Missing required fields" }); + return res.status(400).json({ message: 'Missing required fields' }); } // Create a new workshop @@ -34,21 +34,21 @@ router.post("/create-workshop", async (req: any, res: any) => { try { const savedWorkshop = await newWorkshop.save(); res.status(201).json({ - message: "Workshop created successfully", + message: 'Workshop created successfully', WorkshopID: savedWorkshop, }); } catch (error) { - res.status(401).json({ message: "Failed to create workshop", error }); + res.status(401).json({ message: 'Failed to create workshop', error }); } }); // router.post("/workshops", createWorkshop) // router.get('/workshops/:id', getWorkshop); router.get( - "/workshops/:id", + '/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) diff --git a/api/src/server.ts b/api/src/server.ts index cd7a639..ab45049 100644 --- a/api/src/server.ts +++ b/api/src/server.ts @@ -1,19 +1,19 @@ -import express from "express"; -import bodyParser from "body-parser"; -import connectDB from "./config/db"; +import express from 'express'; +import bodyParser from 'body-parser'; +import connectDB from './config/db'; -import * as routes from "./routes/index"; +import * as routes from './routes/index'; -var cors = require("cors"); +var cors = require('cors'); const app = express(); app.use(cors()); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: true })); -app.use("/user", routes.user); -app.use("/workshop", routes.workshop); +app.use('/user', routes.user); +app.use('/workshop', routes.workshop); connectDB(); -app.listen(process.env.PORT || 8000, () => console.log("Server running...")); +app.listen(process.env.PORT || 8000, () => console.log('Server running...'));