diff --git a/controllers/authorApiRouter.js b/controllers/authorApiRouter.js index 55afbe4..c1264ce 100755 --- a/controllers/authorApiRouter.js +++ b/controllers/authorApiRouter.js @@ -1,10 +1,10 @@ -const authorApiRouter = require('express').Router() +const authorApiRouter = require("express").Router(); -authorApiRouter.get('/', (request, response) => { - response.json({ - authors: "Alok Kumar Sahoo 😉, Rajarshee Basu 😋, Abhipsa Mohapatra 🤭", - message: "The API Works! 🎊" - }) -}) +authorApiRouter.get("/", (request, response) => { + response.json({ + authors: "Alok Kumar Sahoo 😉, Rajarshee Basu 😋, Abhipsa Mohapatra 🤭", + message: "The API Works! 🎊", + }); +}); -module.exports = authorApiRouter \ No newline at end of file +module.exports = authorApiRouter; diff --git a/models/assignmentModel.js b/models/assignmentModel.js index 30e1c13..ef162d8 100644 --- a/models/assignmentModel.js +++ b/models/assignmentModel.js @@ -1,28 +1,28 @@ -const mongoose = require('mongoose'); +const mongoose = require("mongoose"); const assignmentSchema = mongoose.Schema({ - assignmentId: { - type: int, - required: true, - }, - assignmentName: { - type: String, - required: true, - }, - grade: { - type: String, - required: true, - }, - dateDue: { - type: Date, - required: true, - }, - course: { - type: mongoose.Schema.ObjectId, - ref: 'Course', - }, - student: { - type: mongoose.Schema.ObjectId, - ref: 'Student', - }, + assignmentId: { + type: int, + required: true, + }, + assignmentName: { + type: String, + required: true, + }, + grade: { + type: String, + required: true, + }, + dateDue: { + type: Date, + required: true, + }, + course: { + type: mongoose.Schema.ObjectId, + ref: "Course", + }, + student: { + type: mongoose.Schema.ObjectId, + ref: "Student", + }, }); diff --git a/models/branchModel.js b/models/branchModel.js index 4dca80c..6fff2a6 100644 --- a/models/branchModel.js +++ b/models/branchModel.js @@ -1,16 +1,16 @@ -const mongoose = require('mongoose') +const mongoose = require("mongoose"); const branchSchema = mongoose.Schema({ - branchId: { - type: String, - required: true - }, - branchName: { - type: String, - required: true - }, - branchProgramme: { - type: String, - required: true - } -}) \ No newline at end of file + branchId: { + type: String, + required: true, + }, + branchName: { + type: String, + required: true, + }, + branchProgramme: { + type: String, + required: true, + }, +}); diff --git a/models/courseModel.js b/models/courseModel.js index b872db1..b421d16 100644 --- a/models/courseModel.js +++ b/models/courseModel.js @@ -1,20 +1,20 @@ -const mongoose = require('mongoose') +const mongoose = require("mongoose"); const courseSchema = mongoose.Schema({ - courseId: { - type: String, - required: true - }, - courseName: { - type: String, - required: true - }, - courseCredits: { - type: Number, - required: true - }, - courseMarks: { - type: mongoose.Schema.Types.ObjectId, - ref: 'theoryMarks' - } -}) \ No newline at end of file + courseId: { + type: String, + required: true, + }, + courseName: { + type: String, + required: true, + }, + courseCredits: { + type: Number, + required: true, + }, + courseMarks: { + type: mongoose.Schema.Types.ObjectId, + ref: "theoryMarks", + }, +}); diff --git a/models/facultyModel.js b/models/facultyModel.js index 26c8259..d789c97 100644 --- a/models/facultyModel.js +++ b/models/facultyModel.js @@ -1,38 +1,38 @@ -const mongoose = require('mongoose'); +const mongoose = require("mongoose"); const facultySchema = mongoose.Schema({ - facultyId: { - type: String, - required: true, - }, - facultyName: { - type: String, - required: true, - }, - qualification: { - type: String, - required: true, - }, - experience: { - type: String, - required: true, - }, - phone: { - type: String, - required: true, - }, - email: { - type: String, - required: true, - }, - dateOfJoining: { - type: Date, - required: true, - }, - coursesTeaching: [ - { - type: mongoose.Schema.ObjectId, - ref: 'Courses', - }, - ], + facultyId: { + type: String, + required: true, + }, + facultyName: { + type: String, + required: true, + }, + qualification: { + type: String, + required: true, + }, + experience: { + type: String, + required: true, + }, + phone: { + type: String, + required: true, + }, + email: { + type: String, + required: true, + }, + dateOfJoining: { + type: Date, + required: true, + }, + coursesTeaching: [ + { + type: mongoose.Schema.ObjectId, + ref: "Courses", + }, + ], }); diff --git a/models/studentModel.js b/models/studentModel.js index 591ac00..40ca976 100755 --- a/models/studentModel.js +++ b/models/studentModel.js @@ -1,34 +1,34 @@ -const mongoose = require('mongoose') +const mongoose = require("mongoose"); const studentSchema = mongoose.Schema({ - studentId: { - type: String, - required: true, - }, - studentName: { - type: String, - required: true, - }, - studentProgramme: { - type: String, - required: true, - }, - studentBranch: { - type: mongoose.Schema.Types.ObjectId, - ref: 'Branches', - }, - studentStartYear: { - type: Number, - required: true, - }, - studentEndYear: { - type: Number, - required: true, - }, - studentCourses: [ - { - type: mongoose.Schema.Types.ObjectId, - ref: 'Courses' - } - ] -}) \ No newline at end of file + studentId: { + type: String, + required: true, + }, + studentName: { + type: String, + required: true, + }, + studentProgramme: { + type: String, + required: true, + }, + studentBranch: { + type: mongoose.Schema.Types.ObjectId, + ref: "Branches", + }, + studentStartYear: { + type: Number, + required: true, + }, + studentEndYear: { + type: Number, + required: true, + }, + studentCourses: [ + { + type: mongoose.Schema.Types.ObjectId, + ref: "Courses", + }, + ], +}); diff --git a/models/teacherModel.js b/models/teacherModel.js new file mode 100644 index 0000000..d2ab00e --- /dev/null +++ b/models/teacherModel.js @@ -0,0 +1,32 @@ +const mongoose = require("mongoose"); + +const teacherSchema = mongoose.Schema({ + teacherId: { + type: String, + required: true, + }, + teacherName: { + type: String, + required: true, + }, + teacherMajorSubject: { + type: String, + required: true, + }, + teacherFacultyBranch: { + type: mongoose.Schema.Types.ObjectId, + ref: "Branches", + }, + teacherStartYear: { + type: Number, + required: true, + }, + teacherPayrollAmount: { + type: Number, + required: true, + }, + teacherPayDate: { + type: Date, + required: true, + }, +}); diff --git a/models/theoryMarkModel.js b/models/theoryMarkModel.js index fa70c76..83f0e99 100644 --- a/models/theoryMarkModel.js +++ b/models/theoryMarkModel.js @@ -1,7 +1,7 @@ -const mongoose = require('mongoose') +const mongoose = require("mongoose"); const theoryMarkModelSchema = mongoose.Schema({ - midsemMarks: Number, - quizMarks: Number, - endsemMarks: Number, -}) \ No newline at end of file + midsemMarks: Number, + quizMarks: Number, + endsemMarks: Number, +}); diff --git a/server.js b/server.js index 66588f4..39965e8 100755 --- a/server.js +++ b/server.js @@ -10,29 +10,29 @@ const config = require("./utils/config"); const middleware = require("./utils/middleware"); const logger = require("./utils/logger"); -const author = require('./controllers/authorApiRouter') +const author = require("./controllers/authorApiRouter"); logger.info("Connecting to", process.env.MONGO_URI); mongoose - .connect(config.MONGO_URI, { - useNewUrlParser: true, - useUnifiedTopology: true, - useCreateIndex: true, - }) - .then((res) => logger.info("Successfully connected to MongoDB Atlas")) - .catch((e) => logger.info("Something bad happened", e)); + .connect(config.MONGO_URI, { + useNewUrlParser: true, + useUnifiedTopology: true, + useCreateIndex: true, + }) + .then((res) => logger.info("Successfully connected to MongoDB Atlas")) + .catch((e) => logger.info("Something bad happened", e)); app.use(morgan("common")); app.use(helmet()); app.use(cors()); app.use(express.json()); -app.use('/authors', author) +app.use("/authors", author); -app.use(middleware.errorHandler) -app.use(middleware.unknownEndpoint) +app.use(middleware.errorHandler); +app.use(middleware.unknownEndpoint); const PORT = config.PORT || 5000; app.listen(PORT, () => { - console.log(`App listening on http://localhost:${PORT}/`); + console.log(`App listening on http://localhost:${PORT}/`); }); diff --git a/utils/config.js b/utils/config.js index 2cfcd7f..22bdfad 100755 --- a/utils/config.js +++ b/utils/config.js @@ -1,11 +1,11 @@ -require('dotenv').config() +require("dotenv").config(); -const PORT = process.env.PORT -const MONGO_URI = process.env.MONGO_URI -const NODE_ENV = process.env.NODE_ENV +const PORT = process.env.PORT; +const MONGO_URI = process.env.MONGO_URI; +const NODE_ENV = process.env.NODE_ENV; module.exports = { - PORT, - MONGO_URI, - NODE_ENV, -} \ No newline at end of file + PORT, + MONGO_URI, + NODE_ENV, +}; diff --git a/utils/logger.js b/utils/logger.js index c92df47..1d32a4e 100755 --- a/utils/logger.js +++ b/utils/logger.js @@ -1,17 +1,17 @@ const error = (...params) => { - console.error(...params) -} + console.error(...params); +}; const warn = (...params) => { - console.warn(...params) -} + console.warn(...params); +}; const info = (...params) => { - console.log(...params); -} + console.log(...params); +}; module.exports = { - error, - warn, - info, -} \ No newline at end of file + error, + warn, + info, +}; diff --git a/utils/middleware.js b/utils/middleware.js index 03525a5..19ee228 100755 --- a/utils/middleware.js +++ b/utils/middleware.js @@ -1,33 +1,33 @@ const logger = require("./logger"); const errorHandler = (error, request, response, next) => { - logger.error(error); - if (error.status) { - return response.status(error.status).json({ - message: error.message, - stack: - process.env.NODE_ENV === "production" - ? "The app is in production 🤓" - : error.stack, - }); - } else { - return response.status(500).json({ - message: error.message, - stack: - process.env.NODE_ENV === "production" - ? "The app is in production 🤓" - : error.stack, - }); - } + logger.error(error); + if (error.status) { + return response.status(error.status).json({ + message: error.message, + stack: + process.env.NODE_ENV === "production" + ? "The app is in production 🤓" + : error.stack, + }); + } else { + return response.status(500).json({ + message: error.message, + stack: + process.env.NODE_ENV === "production" + ? "The app is in production 🤓" + : error.stack, + }); + } - next(error); + next(error); }; const unknownEndpoint = (request, response) => { - response.status(404).json({ error: "Unknown Endpoint 🤔"}) -} + response.status(404).json({ error: "Unknown Endpoint 🤔" }); +}; module.exports = { - errorHandler, - unknownEndpoint, -} + errorHandler, + unknownEndpoint, +};