Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f34f53d
Implemented hashing and dehashing while signup and sign in with bcryp…
goutham03062001 Apr 18, 2023
0e0e401
created attendance.js and attendanceSchema in it
Aastha-S-Rai Jun 14, 2023
b9407ff
#56 updated Schema and export in attendance.js
Aastha-S-Rai Jun 14, 2023
90f5852
#71 CRUD operation for attendance model
Aastha-S-Rai Jun 14, 2023
75c2ebd
create subject model
ANKIT638-ux Jun 14, 2023
ae1f7d4
58-create_subject_model_1
ANKIT638-ux Jun 15, 2023
d536f47
58 Create subject model2
ANKIT638-ux Jun 15, 2023
8ca8b44
crud for group model
Parikshit-007 Jun 16, 2023
0dc8569
replacedd require with import
Parikshit-007 Jun 16, 2023
6fd9ddf
Added PR Template
VinitChawda06 Jun 19, 2023
b01b0b2
created an schema for the otp store and made the required changes to …
Jun 20, 2023
88da452
made Otpid to uid in otpschema
Jun 20, 2023
c2a1454
Updated Changes and resolved the issue
VinitChawda06 Jun 21, 2023
8b3f984
Issues fixes#93
VinitChawda06 Jun 21, 2023
f0f2cf7
Merge pull request #94 from tcet-opensource/93-Created-Pull_req_temp
Hitansh159 Jun 22, 2023
e2c50ef
add organization model
Jun 24, 2023
69182ea
resolved conflicts arised due to change in structure
Hitansh159 Jun 27, 2023
f0971b1
Merge pull request #100 from tcet-opensource/goutham03062001-#31-save…
Hitansh159 Jun 27, 2023
78604ad
added logger import back in models/user.js
Hitansh159 Jun 27, 2023
6a2ef30
Merge pull request #74 from tcet-opensource/56-create-attendance-model
TejasNair9977 Jun 27, 2023
16d4b37
Merge pull request #85 from tcet-opensource/71-create-curd-operation-…
TejasNair9977 Jun 27, 2023
d632506
Merge pull request #87 from tcet-opensource/58-create_subject_model
TejasNair9977 Jun 27, 2023
d6a5235
Merge branch 'development' into 51-create_CRUD_operations_for_group_m…
TejasNair9977 Jun 27, 2023
e5fa69e
Merge pull request #90 from tcet-opensource/51-create_CRUD_operations…
TejasNair9977 Jun 27, 2023
ae11309
Merge pull request #99 from tcet-opensource/72-organization_model
TejasNair9977 Jun 27, 2023
112bdf7
refactored and restructured the code
Hitansh159 Jun 27, 2023
044cc1a
Merge pull request #98 from tcet-opensource/29_Otp_Store
Hitansh159 Jun 27, 2023
be052ec
fixed syntax according to eslint
Hitansh159 Jun 27, 2023
548d127
added eslint script and git precommit hook
Hitansh159 Jun 27, 2023
6510e79
Merge pull request #101 from tcet-opensource/40-create_a_eslint_hook_…
Hitansh159 Jun 28, 2023
ee83a2e
Removed UID from the file
VinitChawda06 Jun 29, 2023
a204ac9
Merge pull request #106 from tcet-opensource/105-Update-Accreditation…
Hitansh159 Jun 29, 2023
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
17 changes: 17 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Description
Briefly describe the changes made in this pull request.

## Fixes
Specify the related issues or tickets that this pull request fixes (e.g., Fixes #123).

## Checklist
<!-- add x inside brackets for ticking the checkbox eg - [x] -->
- [ ] Code follows project's style guidelines.
- [ ] Changes are documented appropriately.

## Notes
Add any additional notes or context that might be useful for reviewers.



#### (PS → Make Sure Pull request title is meaningful.)
14 changes: 7 additions & 7 deletions controller/auth.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import util, {logger} from "#util";
import OTPStore from "#models/otpStore";
import util, { logger } from "#util";
import { authenticateUser, userExists, updatePassword } from "#services/user";

const otpStore = {};

async function login(req, res) {
const { id, password } = req.body;
try {
Expand All @@ -17,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 @@ -36,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);
otpStore[uid] = otp;
await OTPStore.update({ uid }, { otp });
util.sendOTP(emailId, otp);
res.json({ res: "otp sent to emailID" });
} else {
Expand All @@ -46,12 +45,13 @@ async function sendOTP(req, res) {

async function resetPassword(req, res) {
const { uid, otp, password } = req.body;
if (otpStore[uid] === otp) {
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 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
6 changes: 2 additions & 4 deletions models/accreditation.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
import connector from "#models/databaseUtil";

const accreditationSchema = {
uid: { type: String, unique: true, required: true },
accreditationName: { type: String, required: true },
agencyName: { type: String, required: true },
dateofAccreditation: { type: Date, required: true },
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);
return res;
}

async function create(uid, accreditationName, agencyName, dateofAccreditation, dateofExpiry) {
async function create(accreditationName, agencyName, dateofAccreditation, dateofExpiry) {
const accreditation = new Accreditation({
accreditationName,
agencyName,
uid,
dateofAccreditation,
dateofExpiry,
});
Expand Down
39 changes: 39 additions & 0 deletions models/attendance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import connector from "./databaseUtil";

connector.set("debug", true);

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

const Attendance = connector.model("Attendance", attendanceSchema);

async function create(date, time, absentees) {
const attendance = new Attendance({
date,
time,
absentees,
});
const newAttendence = await attendance.save();
return newAttendence;
}

async function remove(filter) {
const res = await Attendance.findOneAndDelete(filter);
return res;
}

async function grantAttendance(roll, date) {
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;
53 changes: 50 additions & 3 deletions models/group.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,55 @@
import connector from "#models/databaseUtil";

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

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;
}
}

async function getGroupById(groupId) {
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;
}
}

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

const groupModel = new connector.model('group', groupSchema);
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
16 changes: 16 additions & 0 deletions models/organization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import connector from "./databaseUtil";

const organizationSchema = {
parent: { type: connector.Schema.Types.ObjectId, ref: "Organization", required: "true" },
orgID: { type: String, required: true },
orgName: { type: String, required: true },
orgAddress: { type: String, required: true },
orgInfra: [{ type: connector.Schema.Types.ObjectId, ref: "Infrastructure", required: "true" }],
accreditation: { type: connector.Schema.Types.ObjectId, ref: "Accrediation", required: "true" },
department: [{ type: connector.Schema.Types.ObjectId, ref: "Department", required: "true" }],
employees: [{ type: connector.Schema.Types.ObjectId, ref: "Faculty", required: "true" }],

};

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

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

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

async function remove(filter) {
const res = await OTPStore.findOneAndDelete(filter);
return res;
}

async function create(uid, otp) {
const otpStore = new OTPStore({
uid,
otp,
});
const otpDoc = await otpStore.save();
return otpDoc;
}

async function read(filter, limit = 1) {
const otpData = await OTPStore.find(filter).limit(limit);
return otpData;
}

async function update(filter, updateObject) {
const otpDoc = await OTPStore.findOneAndUpdate(filter, updateObject, { upsert: true, new: true });
return otpDoc;
}

export default {
create, read, update, remove,
};
26 changes: 26 additions & 0 deletions models/subject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { connector } = require("#models/databaseUtil");

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
reccTextbooks: { type: [String], required: true },
refBooks: { type: [String], required: true },
evalScheme: { type: [Number], required: true },
maxMarks: { type: Number, required: true },
};

// eslint-disable-next-line no-unused-vars
const subjectcontentModel = connector.model("subjectcontent", subjectcontentSchema);
Loading