Skip to content

Commit

Permalink
prettier pt 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophiahooley committed Nov 10, 2024
1 parent fb9c9de commit 7c2a037
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 55 deletions.
12 changes: 6 additions & 6 deletions api/src/config/aws.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
};
Expand All @@ -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
Expand All @@ -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');
});
10 changes: 5 additions & 5 deletions api/src/config/db.ts
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions api/src/controllers/workshopController.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 });
}
};

Expand All @@ -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 });
}
};

Expand Down
10 changes: 5 additions & 5 deletions api/src/model/Workshop.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,20 +11,20 @@ interface IWorkshop extends Document {

// workshop schema
const WorkshopSchema: Schema<IWorkshop> = 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<void> {
this.textContent = newContent;
await this.save();
};

// mongoose model
const Workshop = mongoose.model<IWorkshop>("Workshop", WorkshopSchema);
const Workshop = mongoose.model<IWorkshop>('Workshop', WorkshopSchema);
export { Workshop, IWorkshop };
30 changes: 15 additions & 15 deletions api/src/routes/user.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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 });
Expand Down
22 changes: 11 additions & 11 deletions api/src/routes/workshop.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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
Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions api/src/server.ts
Original file line number Diff line number Diff line change
@@ -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...'));

0 comments on commit 7c2a037

Please sign in to comment.