Skip to content
Open
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
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 0 additions & 1 deletion server/.env.sample

This file was deleted.

43 changes: 30 additions & 13 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
const express = require("express");
const morgan = require("morgan");
const mongoose = require("mongoose");
const cookieParser = require("cookie-parser");
const PORT = 5005;
const PORT = process.env.PORT || 5005;
require("dotenv").config();

// STATIC DATA
// Devs Team - Import the provided files with JSON data of students and cohorts here:
// ...


// INITIALIZE EXPRESS APP - https://expressjs.com/en/4x/api.html#express
// Initialize express app
const app = express();

// DATABASE CONNECTION
const MONGODB_URI = process.env.MONGODB_URI || "mongodb://localhost:27017/cohort-tools-dev";
mongoose
.connect(MONGODB_URI)
.then(async (x) => {
console.log(`Connected to Mongo! Database name: "${x.connections[0].name}"`);
})
.catch((err) => console.error("Error connecting to mongo", err));

// MIDDLEWARE
// Research Team - Set up CORS middleware here:
Expand All @@ -21,16 +26,28 @@ app.use(express.static("public"));
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());


// ROUTES - https://expressjs.com/en/starter/basic-routing.html
// Devs Team - Start working on the routes here:
// ...
// Documentation route
app.get("/docs", (req, res) => {
res.sendFile(__dirname + "/views/docs.html");
});

// Import route handlers
const cohortRoutes = require("./routes/cohort.routes");
const studentRoutes = require("./routes/student.routes");

// START SERVER
// API Routes
app.use("/api/cohorts", cohortRoutes);
app.use("/api/students", studentRoutes);

// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(err.status || 500).json({
message: err.message || "Internal server error",
});
});

// Start server
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
});
6 changes: 6 additions & 0 deletions server/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = {
PORT: process.env.PORT || 5005,
MONGODB_URI: process.env.MONGODB_URI || "mongodb://localhost:27017/cohort-tools-dev",
};

module.exports = config;
21 changes: 21 additions & 0 deletions server/models/Cohort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const mongoose = require("mongoose");
const { Schema } = mongoose;

const cohortSchema = new Schema(
{
inProgress: { type: Boolean, default: true },
cohortSlug: { type: String, required: true, unique: true },
cohortName: { type: String, required: true },
program: { type: String, required: true },
campus: { type: String, required: true },
startDate: { type: Date, required: true },
endDate: { type: Date, required: true },
programManager: { type: String, required: true },
leadTeacher: { type: String, required: true },
totalHours: { type: Number, required: true },
createdAt: { type: Date, default: Date.now },
},
{ timestamps: true }
);

module.exports = mongoose.model("Cohort", cohortSchema);
21 changes: 21 additions & 0 deletions server/models/Student.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const mongoose = require("mongoose");
const { Schema } = mongoose;

const studentSchema = new Schema(
{
firstName: { type: String, required: true },
lastName: { type: String, required: true },
email: { type: String, required: true, unique: true },
phone: { type: String },
linkedinUrl: { type: String },
languages: [{ type: String }],
program: { type: String, required: true },
background: { type: String },
image: { type: String },
cohort: { type: Schema.Types.ObjectId, ref: "Cohort", required: true },
projects: [{ type: String }],
},
{ timestamps: true }
);

module.exports = mongoose.model("Student", studentSchema);
Loading