Skip to content

Commit d23d09f

Browse files
authored
Merge pull request #102 from tcet-opensource/development
[FEAT] Added new workflow settings
2 parents 0d35992 + a204ac9 commit d23d09f

File tree

18 files changed

+608
-78
lines changed

18 files changed

+608
-78
lines changed

.github/pull_request_template.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Description
2+
Briefly describe the changes made in this pull request.
3+
4+
## Fixes
5+
Specify the related issues or tickets that this pull request fixes (e.g., Fixes #123).
6+
7+
## Checklist
8+
<!-- add x inside brackets for ticking the checkbox eg - [x] -->
9+
- [ ] Code follows project's style guidelines.
10+
- [ ] Changes are documented appropriately.
11+
12+
## Notes
13+
Add any additional notes or context that might be useful for reviewers.
14+
15+
16+
17+
#### (PS → Make Sure Pull request title is meaningful.)

controller/auth.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import util, {logger} from "#util";
1+
import OTPStore from "#models/otpStore";
2+
import util, { logger } from "#util";
23
import { authenticateUser, userExists, updatePassword } from "#services/user";
34

4-
const otpStore = {};
5-
65
async function login(req, res) {
76
const { id, password } = req.body;
87
try {
@@ -17,7 +16,7 @@ async function login(req, res) {
1716
userDetails.token = token;
1817
res.json({ res: "welcome", user: userDetails });
1918
} catch (error) {
20-
logger.error("Error while login", error)
19+
logger.error("Error while login", error);
2120
if (error.name === "UserDoesNotExist") {
2221
res.status(403);
2322
res.json({ err: "Incorrect ID password" });
@@ -36,7 +35,7 @@ async function sendOTP(req, res) {
3635
const { uid, emailId } = req.body;
3736
if (await userExists(uid, emailId)) {
3837
const otp = Math.floor(1000 + Math.random() * 9000);
39-
otpStore[uid] = otp;
38+
await OTPStore.update({ uid }, { otp });
4039
util.sendOTP(emailId, otp);
4140
res.json({ res: "otp sent to emailID" });
4241
} else {
@@ -46,12 +45,13 @@ async function sendOTP(req, res) {
4645

4746
async function resetPassword(req, res) {
4847
const { uid, otp, password } = req.body;
49-
if (otpStore[uid] === otp) {
48+
const storedOtp = await OTPStore.read({ uid });
49+
if (storedOtp[0].otp === `${otp}`) {
5050
try {
5151
await updatePassword(uid, password);
5252
res.json({ res: "successfully updated password" });
5353
} catch (error) {
54-
logger.log("Error while updating", error)
54+
logger.log("Error while updating", error);
5555
res.status(500);
5656
if (error.name === "UpdateError") res.json({ err: "Something went wrong while updating password" });
5757
else res.json({ err: "something went wrong" });

controller/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ async function addUser(req, res) {
99
const newUser = await createUser(name, password, emailId, uid, userType);
1010
res.json({ res: `added user ${newUser.id}` });
1111
} catch (error) {
12-
logger.error("Error while inserting", error)
13-
res.status(500)
12+
logger.error("Error while inserting", error);
13+
res.status(500);
1414
res.json({ err: "Error while inserting in DB" });
1515
}
1616
}

middleware/auth.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import jwt from "jsonwebtoken";
2-
import util, {logger} from "#util";
2+
import util from "#util";
33

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

1616
req.user = payload.data;
1717
next();
18+
return true;
1819
} catch (error) {
19-
res.status(403)
20-
res.send({err:"Unauthorized"});
20+
res.status(403);
21+
res.send({ err: "Unauthorized" });
22+
return false;
2123
}
2224
}
2325

models/accreditation.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import connector from "#models/databaseUtil";
22

33
const accreditationSchema = {
4-
uid: { type: String, unique: true, required: true },
54
accreditationName: { type: String, required: true },
65
agencyName: { type: String, required: true },
76
dateofAccreditation: { type: Date, required: true },
87
dateofExpiry: { type: Date, required: true },
98
};
109

11-
const Accreditation = new connector.model("Accreditation", accreditationSchema);
10+
const Accreditation = connector.model("Accreditation", accreditationSchema);
1211

1312
async function remove(filter) {
1413
const res = await Accreditation.findOneAndDelete(filter);
1514
return res;
1615
}
1716

18-
async function create(uid, accreditationName, agencyName, dateofAccreditation, dateofExpiry) {
17+
async function create(accreditationName, agencyName, dateofAccreditation, dateofExpiry) {
1918
const accreditation = new Accreditation({
2019
accreditationName,
2120
agencyName,
22-
uid,
2321
dateofAccreditation,
2422
dateofExpiry,
2523
});

models/attendance.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import connector from "./databaseUtil";
2+
3+
connector.set("debug", true);
4+
5+
const attendanceSchema = {
6+
date: { type: Date, required: true },
7+
time: { type: String, required: true },
8+
absentees: { type: Array },
9+
};
10+
11+
const Attendance = connector.model("Attendance", attendanceSchema);
12+
13+
async function create(date, time, absentees) {
14+
const attendance = new Attendance({
15+
date,
16+
time,
17+
absentees,
18+
});
19+
const newAttendence = await attendance.save();
20+
return newAttendence;
21+
}
22+
23+
async function remove(filter) {
24+
const res = await Attendance.findOneAndDelete(filter);
25+
return res;
26+
}
27+
28+
async function grantAttendance(roll, date) {
29+
const res = await Attendance.findOneAndUpdate(
30+
date,
31+
{ $pull: { absentees: roll } },
32+
{ new: true },
33+
);
34+
return res;
35+
}
36+
37+
export default {
38+
create, remove, grantAttendance,
39+
};

models/faculty.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const { connector } = require('./databaseUtil');
1+
const { connector } = require("./databaseUtil");
22

3-
const facultySchema = new mongoose.Schema({
3+
const facultySchema = {
44
name: {
55
type: String,
66
required: true,
77
},
88
department: {
9-
type: mongoose.Schema.Types.ObjectId,
10-
ref: 'Department',
9+
type: connector.Schema.Types.ObjectId,
10+
ref: "Department",
1111
required: true,
1212
},
1313
empType: {
@@ -19,7 +19,7 @@ const facultySchema = new mongoose.Schema({
1919
required: true,
2020
},
2121
preferredSubjects: {
22-
type: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Subject' }],
22+
type: [{ type: connector.Schema.Types.ObjectId, ref: "Subject" }],
2323
required: true,
2424
},
2525
profileLink: {
@@ -87,8 +87,8 @@ const facultySchema = new mongoose.Schema({
8787
type: Date,
8888
default: Date.now,
8989
},
90-
});
90+
};
9191

92-
const Faculty = connector.model('Faculty', facultySchema);
92+
const Faculty = connector.model("Faculty", facultySchema);
9393

9494
module.exports = Faculty;

models/group.js

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,55 @@
11
import connector from "#models/databaseUtil";
22

33
const groupSchema = {
4-
groupName: { type: String, required: true },
5-
studentIds: { type: [Number], required: true }, //array of number
4+
groupName: { type: String, required: true },
5+
studentIds: { type: [Number], required: true },
6+
};
7+
8+
const groupModel = connector.model("group", groupSchema);
9+
10+
async function createGroup(groupData) {
11+
try {
12+
const newGroup = await groupModel.create(groupData);
13+
return newGroup;
14+
} catch (error) {
15+
console.error("Error creating group:", error);
16+
return null;
17+
}
18+
}
19+
20+
async function getGroupById(groupId) {
21+
try {
22+
const group = await groupModel.findById(groupId);
23+
return group;
24+
} catch (error) {
25+
console.error("Error retrieving group:", error);
26+
return null;
27+
}
28+
}
29+
30+
async function updateGroup(groupId, updateData) {
31+
try {
32+
const updatedGroup = await groupModel.findByIdAndUpdate(groupId, updateData, { new: true });
33+
return updatedGroup;
34+
} catch (error) {
35+
console.error("Error updating group:", error);
36+
return null;
37+
}
38+
}
39+
40+
async function deleteGroup(groupId) {
41+
try {
42+
const deletedGroup = await groupModel.findByIdAndDelete(groupId);
43+
return deletedGroup;
44+
} catch (error) {
45+
console.error("Error deleting group:", error);
46+
return null;
47+
}
648
}
749

8-
const groupModel = new connector.model('group', groupSchema);
50+
export default {
51+
createGroup,
52+
getGroupById,
53+
updateGroup,
54+
deleteGroup,
55+
};

models/infra.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const infrastructureSchema = {
88
capacity: { type: Number, required: true },
99
};
1010

11-
const Infrastructure = new connector.model("Infrastructure", infrastructureSchema);
11+
const Infrastructure = connector.model("Infrastructure", infrastructureSchema);
1212

1313
async function remove(filter) {
1414
const res = await Infrastructure.findOneAndDelete(filter);

models/module.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import connector from '#models/databaseUtil';
1+
import connector from "#models/databaseUtil";
22

33
const moduleSchema = {
44
moduleNo: { type: Number, required: true },
@@ -9,7 +9,7 @@ const moduleSchema = {
99
cognitiveLevels: [{ type: String, required: true }],
1010
};
1111

12-
const Module = new connector.model('Module', moduleSchema);
12+
const Module = connector.model("Module", moduleSchema);
1313

1414
async function remove(filter) {
1515
const res = await Module.findOneAndDelete(filter);
@@ -22,7 +22,7 @@ async function create(
2222
moduleOutcome,
2323
moduleContents,
2424
hrsPerModule,
25-
cognitiveLevels
25+
cognitiveLevels,
2626
) {
2727
const module = new Module({
2828
moduleNo,

0 commit comments

Comments
 (0)