Skip to content
Merged
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
11 changes: 5 additions & 6 deletions controller/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import OTPStore from "#models/otpStore";
import util, {logger} from "#util";
import util, { logger } from "#util";
import { authenticateUser, userExists, updatePassword } from "#services/user";

async function login(req, res) {
Expand All @@ -16,7 +16,7 @@ async function login(req, res) {
userDetails.token = token;
res.json({ res: "welcome", user: userDetails });
} catch (error) {
logger.error("Error while login", error)
logger.error("Error while login", error);
if (error.name === "UserDoesNotExist") {
res.status(403);
res.json({ err: "Incorrect ID password" });
Expand All @@ -35,7 +35,7 @@ async function sendOTP(req, res) {
const { uid, emailId } = req.body;
if (await userExists(uid, emailId)) {
const otp = Math.floor(1000 + Math.random() * 9000);
await OTPStore.update({uid: uid}, {otp: otp});
await OTPStore.update({ uid }, { otp });
util.sendOTP(emailId, otp);
res.json({ res: "otp sent to emailID" });
} else {
Expand All @@ -45,13 +45,13 @@ async function sendOTP(req, res) {

async function resetPassword(req, res) {
const { uid, otp, password } = req.body;
const storedOtp = await OTPStore.read({uid: uid});
const storedOtp = await OTPStore.read({ uid });
if (storedOtp[0].otp === `${otp}`) {
try {
await updatePassword(uid, password);
res.json({ res: "successfully updated password" });
} catch (error) {
logger.log("Error while updating", error)
logger.log("Error while updating", error);
res.status(500);
if (error.name === "UpdateError") res.json({ err: "Something went wrong while updating password" });
else res.json({ err: "something went wrong" });
Expand All @@ -60,7 +60,6 @@ async function resetPassword(req, res) {
res.json({ err: "incorrect otp" });
}
}


export default {
validateUser, sendOTP, resetPassword, login,
Expand Down
4 changes: 2 additions & 2 deletions controller/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ async function addUser(req, res) {
const newUser = await createUser(name, password, emailId, uid, userType);
res.json({ res: `added user ${newUser.id}` });
} catch (error) {
logger.error("Error while inserting", error)
res.status(500)
logger.error("Error while inserting", error);
res.status(500);
res.json({ err: "Error while inserting in DB" });
}
}
Expand Down
12 changes: 7 additions & 5 deletions middleware/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import jwt from "jsonwebtoken";
import util, {logger} from "#util";
import util from "#util";

async function authenticateToken(req, res, next) {
const authHeader = req.headers.authorization;
Expand All @@ -9,15 +9,17 @@ async function authenticateToken(req, res, next) {
const payload = jwt.verify(token, process.env.TOKEN_SECRET);
const decryptedIP = util.decrypt(payload.ip);
if (decryptedIP !== req.ip) {
res.status(403)
res.send({err:"Unauthorized"});
res.status(403);
res.send({ err: "Unauthorized" });
}

req.user = payload.data;
next();
return true;
} catch (error) {
res.status(403)
res.send({err:"Unauthorized"});
res.status(403);
res.send({ err: "Unauthorized" });
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion models/accreditation.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const accreditationSchema = {
dateofExpiry: { type: Date, required: true },
};

const Accreditation = new connector.model("Accreditation", accreditationSchema);
const Accreditation = connector.model("Accreditation", accreditationSchema);

async function remove(filter) {
const res = await Accreditation.findOneAndDelete(filter);
Expand Down
10 changes: 6 additions & 4 deletions models/attendance.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import connector from "./databaseUtil";
import Infrastructure from "./infrastructure";

connector.set("debug", true);

const attendanceSchema = {
date: { type: Date, required: true },
time: { type: String, required: true },
absentees: { type: Array },
class: Infrastructure,
};

const Attendance = connector.model("Attendance", attendanceSchema);
Expand All @@ -28,10 +26,14 @@ async function remove(filter) {
}

async function grantAttendance(roll, date) {
const res = await Attendance.findOneAndUpdate(date, {$pull: { absentees: roll } }, { new: true });
const res = await Attendance.findOneAndUpdate(
date,
{ $pull: { absentees: roll } },
{ new: true },
);
return res;
}

export default {
create, remove, grantAttendance,
};
};
14 changes: 7 additions & 7 deletions models/faculty.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { connector } = require('./databaseUtil');
const { connector } = require("./databaseUtil");

const facultySchema = new mongoose.Schema({
const facultySchema = {
name: {
type: String,
required: true,
},
department: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Department',
type: connector.Schema.Types.ObjectId,
ref: "Department",
required: true,
},
empType: {
Expand All @@ -19,7 +19,7 @@ const facultySchema = new mongoose.Schema({
required: true,
},
preferredSubjects: {
type: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Subject' }],
type: [{ type: connector.Schema.Types.ObjectId, ref: "Subject" }],
required: true,
},
profileLink: {
Expand Down Expand Up @@ -87,8 +87,8 @@ const facultySchema = new mongoose.Schema({
type: Date,
default: Date.now,
},
});
};

const Faculty = connector.model('Faculty', facultySchema);
const Faculty = connector.model("Faculty", facultySchema);

module.exports = Faculty;
73 changes: 37 additions & 36 deletions models/group.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
import connector from "#models/databaseUtil";

const groupSchema = {
groupName: { type: String, required: true },
studentIds: { type: [Number], required: true },
groupName: { type: String, required: true },
studentIds: { type: [Number], required: true },
};

const groupModel = new connector.model("group", groupSchema);
const groupModel = connector.model("group", groupSchema);

async function createGroup(groupData) {
try {
const newGroup = await groupModel.create(groupData);
return newGroup;
} catch (error) {
console.error("Error creating group:", error);
return null;
}
try {
const newGroup = await groupModel.create(groupData);
return newGroup;
} catch (error) {
console.error("Error creating group:", error);
return null;
}
}

async function getGroupById(groupId) {
try {
const group = await groupModel.findById(groupId);
return group;
} catch (error) {
console.error("Error retrieving group:", error);
return null;
}
try {
const group = await groupModel.findById(groupId);
return group;
} catch (error) {
console.error("Error retrieving group:", error);
return null;
}
}

async function updateGroup(groupId, updateData) {
try {
const updatedGroup = await groupModel.findByIdAndUpdate(groupId, updateData, { new: true });
return updatedGroup;
} catch (error) {
console.error("Error updating group:", error);
return null;
}
try {
const updatedGroup = await groupModel.findByIdAndUpdate(groupId, updateData, { new: true });
return updatedGroup;
} catch (error) {
console.error("Error updating group:", error);
return null;
}
}

async function deleteGroup(groupId) {
try {
const deletedGroup = await groupModel.findByIdAndDelete(groupId);
return deletedGroup;
} catch (error) {
console.error("Error deleting group:", error);
return null;
}
try {
const deletedGroup = await groupModel.findByIdAndDelete(groupId);
return deletedGroup;
} catch (error) {
console.error("Error deleting group:", error);
return null;
}
}

module.exports = {
createGroup,
getGroupById,
updateGroup,
deleteGroup,
export default {
createGroup,
getGroupById,
updateGroup,
deleteGroup,
};
2 changes: 1 addition & 1 deletion models/infra.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const infrastructureSchema = {
capacity: { type: Number, required: true },
};

const Infrastructure = new connector.model("Infrastructure", infrastructureSchema);
const Infrastructure = connector.model("Infrastructure", infrastructureSchema);

async function remove(filter) {
const res = await Infrastructure.findOneAndDelete(filter);
Expand Down
6 changes: 3 additions & 3 deletions models/module.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import connector from '#models/databaseUtil';
import connector from "#models/databaseUtil";

const moduleSchema = {
moduleNo: { type: Number, required: true },
Expand All @@ -9,7 +9,7 @@ const moduleSchema = {
cognitiveLevels: [{ type: String, required: true }],
};

const Module = new connector.model('Module', moduleSchema);
const Module = connector.model("Module", moduleSchema);

async function remove(filter) {
const res = await Module.findOneAndDelete(filter);
Expand All @@ -22,7 +22,7 @@ async function create(
moduleOutcome,
moduleContents,
hrsPerModule,
cognitiveLevels
cognitiveLevels,
) {
const module = new Module({
moduleNo,
Expand Down
4 changes: 3 additions & 1 deletion models/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ const organizationSchema = {
employees: [{ type: connector.Schema.Types.ObjectId, ref: "Faculty", required: "true" }],

};
const Organization = new connector.model("Organization", organizationSchema);

// eslint-disable-next-line no-unused-vars
const Organization = connector.model("Organization", organizationSchema);
10 changes: 4 additions & 6 deletions models/otpStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import connector from "#models/databaseUtil";

const otpStoreSchema = {
uid: { type: String, unique: true, required: true },
otp: { type: String, unique: true, required: true }
}
otp: { type: String, unique: true, required: true },
};

const OTPStore = connector.model("OTPStore", otpStoreSchema)
const OTPStore = connector.model("OTPStore", otpStoreSchema);

async function remove(filter) {
const res = await OTPStore.findOneAndDelete(filter);
Expand All @@ -15,7 +15,7 @@ async function remove(filter) {
async function create(uid, otp) {
const otpStore = new OTPStore({
uid,
otp
otp,
});
const otpDoc = await otpStore.save();
return otpDoc;
Expand All @@ -31,8 +31,6 @@ async function update(filter, updateObject) {
return otpDoc;
}


export default {
create, read, update, remove,
};

44 changes: 22 additions & 22 deletions models/subject.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
const { connector } = require("#models/databaseUtil");
const { Module } = require("#models/module");
const { Practical} = require("#models/practical");

const subjectcontentSchema = {
courseCode: {type: String, required: true},
courseName: {type: String, required: true},
totalCredit: {type: Number, required: true},
duration: {type: Number, required: true},
subID: {type: String, required: true},
subName: {type:String, required: true},
semester: {type: String, required: true},
ltpCredDist: {type: [Number], required: true},
subType: {type: String, enum: ["open", "professional", "core"], required: true}, // can be open, professional, or core
prerequisites: {type: String, required: true},
courseObjective:{type: String, required: true},
courseOutcomes : [{courseOutcome:{type: String}, RBTLevel: {type:String}}], //this is the modules from syllabus
modules: {type: [Module], required: true},
reccTextbooks: {type: [String], required: true},
refBooks: {type: [String], required: true},
evalScheme: {type: [Number], required: true},
maxMarks: {type: Number, required: true},
practicals: {type: [Practical], required: true}
};
courseCode: { type: String, required: true },
courseName: { type: String, required: true },
totalCredit: { type: Number, required: true },
duration: { type: Number, required: true },
subID: { type: String, required: true },
subName: { type: String, required: true },
semester: { type: String, required: true },
ltpCredDist: { type: [Number], required: true },
subType: { type: String, enum: ["open", "professional", "core"], required: true }, // can be open, professional, or core
prerequisites: { type: String, required: true },
courseObjective: { type: String, required: true },
courseOutcomes: [{
courseOutcome: { type: String },
RBTLevel: { type: String },
}], // this is the modules from syllabus
reccTextbooks: { type: [String], required: true },
refBooks: { type: [String], required: true },
evalScheme: { type: [Number], required: true },
maxMarks: { type: Number, required: true },
};

const subjectcontentModel = new connector.model("subjectcontent", subjectcontentSchema);
// eslint-disable-next-line no-unused-vars
const subjectcontentModel = connector.model("subjectcontent", subjectcontentSchema);
6 changes: 3 additions & 3 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import connector from "#models/databaseUtil";
import { hashPassword, logger } from "#util";
import { hashPassword } from "#util";

connector.set("debug", true);
const userSchema = {
Expand All @@ -17,8 +17,8 @@ async function remove(filter) {
return res;
}

async function create(name, password, emailId, uid, userType) {
password = await hashPassword(password);
async function create(name, pass, emailId, uid, userType) {
const password = await hashPassword(pass);
const user = new User({
name,
password,
Expand Down
Loading