Skip to content

Commit caf7403

Browse files
committed
resolved merge conflict :)
2 parents 1d2c7fd + 06e07d1 commit caf7403

File tree

13 files changed

+331
-27
lines changed

13 files changed

+331
-27
lines changed

controller/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async function login(req, res) {
2222
res.json({ err: "Incorrect ID password" });
2323
} else {
2424
res.status(500);
25-
res.json({ err: "Something is wrong on our side. Try again" });
25+
res.json({ err: "User doesn't exist" });
2626
}
2727
}
2828
}

hooks/pre-commit

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
#!/bin/bash
22

3-
for file in $(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|jsx)$')
3+
# Store staged files in an array
4+
staged_files=($(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|jsx)$'))
5+
flag=0
6+
# Loop through staged files and run ESLint on each
7+
for file in "${staged_files[@]}"
48
do
5-
git show ":$file" | npm run eslint --stdin --stdin-filename "$file"
9+
# Get staged content of the file
10+
staged_content=$(git show ":$file")
11+
12+
# Run ESLint with the staged content and filename
13+
# echo "$staged_content" | npm run eslint -- --stdin
14+
npx eslint $file
615
if [ $? -ne 0 ]; then
716
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
8-
exit 1
17+
flag=1
918
fi
1019
done
20+
21+
if [ $flag -eq 1 ]; then
22+
exit 1
23+
fi

models/activity.js

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

33
const activitySchema = {
4-
course: { type: connector.Schema.Types.ObjectId, ref: 'ActivityBlueprint', required: true },
5-
startTime: { type: Date, required: true },
6-
duration: { type: Number, required: true },
7-
course: { type: connector.Schema.Types.ObjectId, ref: 'Course', required: true },
8-
faculty: { type: connector.Schema.Types.ObjectId, ref: 'Faculty', required: true },
9-
type: {
10-
type: String,
11-
required: true,
12-
enum: ["Lecture", "Practical", "Tutorial"],
13-
},
14-
task: [{
15-
type: connector.Schema.Types.ObjectId,
16-
ref: ['Topic' , 'Practical' , 'Tutorial'],
17-
required: true,
18-
}],
19-
group: { type: connector.Schema.Types.ObjectId, ref: 'Group', required: true },
20-
students: [{ type: connector.Schema.Types.ObjectId, ref: "Student", required: true }],
21-
};
22-
23-
// eslint-disable-next-line no-unused-vars
24-
const Activity = connector.model("Activity", activitySchema);
4+
activityBlueprint: { type: connector.Schema.Types.ObjectId, ref: "ActivityBlueprint", required: true },
5+
startTime: { type: Date, required: true },
6+
duration: { type: Number, required: true },
7+
course: { type: connector.Schema.Types.ObjectId, ref: "Course", required: true },
8+
faculty: { type: connector.Schema.Types.ObjectId, ref: "Faculty", required: true },
9+
type: {
10+
type: String,
11+
required: true,
12+
enum: ["LECTURE", "PRACTICAL", "TUTORIAL"],
13+
},
14+
task: [{
15+
type: connector.Schema.Types.ObjectId,
16+
ref: ["Topic", "Practical", "Tutorial"],
17+
required: true,
18+
}],
19+
group: { type: connector.Schema.Types.ObjectId, ref: "Group", required: true },
20+
students: [{ type: connector.Schema.Types.ObjectId, ref: "Student", required: true }],
21+
};
22+
23+
// eslint-disable-next-line no-unused-vars
24+
const Activity = connector.model("Activity", activitySchema);

models/activityBlueprint.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import connector from "#models/databaseUtil";
2+
3+
const activityBluePrintSchema = {
4+
number: { type: Number, required: true },
5+
academicYearYear: {
6+
type: String,
7+
required: true,
8+
validate: {
9+
validator: (value) => /^2\d{3}$/.test(value),
10+
message: (props) => `${props.value} is not a valid year format starting with "2"!`,
11+
},
12+
},
13+
type: { enum: ["ODD", "EVEN"], required: true },
14+
startDate: { type: Date, required: true },
15+
endDate: { type: Date, required: true },
16+
};
17+
18+
// eslint-disable-next-line no-unused-vars
19+
const ActivityBlueprint = connector.model("ActivityBlueprint", activityBluePrintSchema);

models/assignment.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,33 @@ const assignmentSchema = {
99

1010
// eslint-disable-next-line no-unused-vars
1111
const Assignment = connector.model("Assignment", assignmentSchema);
12+
13+
/// CRUD Operations ///
14+
15+
async function create(assignmentData) {
16+
const assignment = new Assignment(assignmentData);
17+
const assignmentDoc = await assignment.save();
18+
return assignmentDoc;
19+
}
20+
21+
async function read(filter, limit = 1) {
22+
const assignmentDoc = await Assignment.find(filter).limit(limit);
23+
return assignmentDoc;
24+
}
25+
26+
async function update(filter, updateObject, options = { multi: true }) {
27+
const updateResult = await Assignment.updateMany(filter, { $set: updateObject }, options);
28+
return updateResult.acknowledged;
29+
}
30+
31+
async function remove(filter) {
32+
const deleteResult = await Assignment.deleteMany(filter).exec();
33+
return deleteResult.acknowledged;
34+
}
35+
36+
export default {
37+
create,
38+
read,
39+
update,
40+
remove,
41+
};

models/coursework.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import connector from "#models/databaseUtil";
2+
3+
const courseworkSchema = {
4+
student: { type: connector.Schema.Types.ObjectId, ref: "Student", required: true },
5+
type: { type: String, enum: ["onCampus", "offCampus"], required: true },
6+
course: { type: connector.Schema.Types.ObjectId, ref: "Course", required: true },
7+
task: { type: connector.Schema.Types.ObjectId, refPath: "objectID", required: true },
8+
objectID: { type: String, enum: ["Practical", "Tutorial", "Assignment"], required: true },
9+
activity: { type: connector.Schema.Types.ObjectId, ref: "Activity", required: true },
10+
marks: { type: Number, required: true },
11+
};
12+
13+
// eslint-disable-next-line no-unused-vars
14+
const Coursework = connector.model("Coursework", courseworkSchema);

models/exam.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import connector from "#models/databaseUtil";
2+
3+
const examSchema = {
4+
date: { type: Date, required: true },
5+
startTime: { type: Date, required: true },
6+
duration: { type: Number, required: true },
7+
supervisor: { type: connector.Schema.Types.ObjectId, ref: "Faculty", required: "true" },
8+
infrastructure: { type: connector.Schema.Types.ObjectId, ref: "Infrastructure", required: "true" },
9+
course: { type: connector.Schema.Types.ObjectId, ref: "Course", required: "true" },
10+
};
11+
12+
const Exam = connector.model("Exam", examSchema);
13+
14+
async function create(examData) {
15+
const exam = new Exam(examData);
16+
const examDoc = await exam.save();
17+
return examDoc;
18+
}
19+
20+
async function read(filter, limit = 1) {
21+
const examDoc = await Exam.find(filter).limit(limit);
22+
return examDoc;
23+
}
24+
25+
async function update(filter, updateObject, options = { multi: true }) {
26+
const updateResult = await Exam.updateMany(filter, { $set: updateObject }, options);
27+
return updateResult.acknowledged;
28+
}
29+
30+
async function remove(filter) {
31+
const deleteResult = await Exam.deleteMany(filter).exec();
32+
return deleteResult.acknowledged;
33+
}
34+
35+
export default {
36+
create,
37+
read,
38+
update,
39+
remove,
40+
};

models/paper.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import connector from "#models/databaseUtil";
2+
3+
const paperSchema = {
4+
answerSheetID: { type: String, required: true },
5+
exam: [{ type: connector.Schema.Types.ObjectId, ref: "Exam", required: true }],
6+
student: [{ type: connector.Schema.Types.ObjectId, ref: "Student", required: true }],
7+
checkedBy: [{ type: connector.Schema.Types.ObjectId, ref: "Faculty", required: true }],
8+
mark: { type: Number, required: true },
9+
};
10+
11+
// eslint-disable-next-line no-unused-vars
12+
const Paper = connector.model("Paper", paperSchema);

models/practical.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,38 @@ const practicalSchema = {
1414

1515
// eslint-disable-next-line no-unused-vars
1616
const Practical = connector.model("Practical", practicalSchema);
17+
18+
// CRUD operations
19+
async function remove(filter) {
20+
const deleteResult = await Practical.deleteMany(filter);
21+
return deleteResult.acknowledged;
22+
}
23+
24+
async function create(practicalData) {
25+
const {
26+
no, type, title, hours, cognitiveLevels,
27+
} = practicalData;
28+
const practical = new Practical({
29+
no,
30+
type,
31+
title,
32+
hours,
33+
cognitiveLevels,
34+
});
35+
const practicalDoc = await practical.save();
36+
return practicalDoc;
37+
}
38+
39+
async function read(filter, limit = 1) {
40+
const practicalDoc = await Practical.find(filter).limit(limit);
41+
return practicalDoc;
42+
}
43+
44+
async function update(filter, updateObject, options = { multi: true }) {
45+
const updateResult = await Practical.updateMany(filter, { $set: updateObject }, options);
46+
return updateResult.acknowledged;
47+
}
48+
49+
export default {
50+
create, read, update, remove,
51+
};

models/topic.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,34 @@ const topicSchema = {
44
title: { type: String, required: true },
55
};
66
// eslint-disable-next-line no-unused-vars
7-
const Topic = connector.model("topic", topicSchema);
7+
const Topic = connector.model("Topic", topicSchema);
8+
9+
// CURD operations
10+
async function create(topicData) {
11+
const {
12+
title,
13+
} = topicData;
14+
const topic = new Topic({
15+
title,
16+
});
17+
const topicDoc = await topic.save();
18+
return topicDoc;
19+
}
20+
21+
async function read(filter, limit = 1) {
22+
const topicDoc = await Topic.find(filter).limit(limit);
23+
return topicDoc;
24+
}
25+
26+
async function update(filter, updateObject, options = { multi: true }) {
27+
const updateResult = await Topic.updateMany(filter, { $set: updateObject }, options);
28+
return updateResult.acknowledged;
29+
}
30+
31+
async function remove(filter) {
32+
const deleteResult = await Topic.deleteMany(filter);
33+
return deleteResult.acknowledged;
34+
}
35+
export default {
36+
create, remove, update, read,
37+
};

0 commit comments

Comments
 (0)