Skip to content

Commit 77369c8

Browse files
Merge branch 'development' into 254-topics.endpoints
2 parents fe5ceee + 32c4ac3 commit 77369c8

39 files changed

+1696
-131
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
env:
1111
TOKEN_SECRET: ${{ secrets.TOKEN_SECRET }}
1212
DB_URL: ${{ secrets.DB_URL }}
13+
ENVIRONMENT: ${{ secrets.ENVIRONMENT }}
1314

1415
permissions:
1516
contents: read

.husky/pre-commit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
# npm test
5+
npx lint-staged
6+
7+
if [ "$(uname)" == "Darwin" ]; then
8+
npm run test
9+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
10+
npm run test
11+
elif [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
12+
npm run testWin
13+
fi

.lintstagedrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"*.js": [
3+
"prettier --write",
4+
"eslint --fix"
5+
]
6+
}

_apidoc.js

Lines changed: 157 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,68 @@
672672
* attainment as per Bloom's Taxanomy (L1-L6).
673673
*/
674674

675+
// ------------------------------------------------------------------------------------------
676+
// Attendance.
677+
// ------------------------------------------------------------------------------------------
678+
679+
/**
680+
* @api {post} /attendance/add Add Attendance
681+
* @apiName AddAttendance
682+
* @apiGroup Attendance
683+
* @apiDescription Add a new attendance.
684+
*
685+
* @apiBody {String} student Student name.
686+
* @apiBody {String} course Course name.
687+
* @apiBody {Number} monthlyAttended Monthly attendance of student.
688+
* @apiBody {Number} monthlyOccured Monthly occured.
689+
* @apiBody {Number} cumulativeAttended sum of attendance of student.
690+
* @apiBody {Number} cumulativeOccured sum of occured.
691+
*
692+
* @apiSuccess {String} res Response message.
693+
* @apiError (Error 500) UserNotFound The of the User was not found
694+
*
695+
* @apiSuccessExample Success-Response:
696+
* HTTP/1.1 200 OK
697+
* {
698+
* "res": "added attendance Example Attendance"
699+
* }
700+
*
701+
* @apiErrorExample Error-Response:
702+
* HTTP/1.1 500 Internal Server Error
703+
* {
704+
* "err": "Error while inserting in DB"
705+
* }
706+
*/
707+
708+
// ------------------------------------------------------------------------------------------
709+
// Exam.
710+
// ------------------------------------------------------------------------------------------
711+
712+
/**
713+
* @api {post} /exam/add Add Exam
714+
* @apiName AddExam
715+
* @apiExam Exam
716+
* @apiDescription Add a new exam.
717+
*
718+
* @apiBody {String} title Exam title.
719+
* @apiBody {ObjectId[]} students Array of student ObjectIDs.
720+
*
721+
* @apiSuccess {String} res Response message.
722+
* @apiError (Error 500) ExamAddError Error while adding the exam
723+
*
724+
* @apiSuccessExample Success-Response:
725+
* HTTP/1.1 200 OK
726+
* {
727+
* "res": "added exam Example Exam"
728+
* }
729+
*
730+
* @apiErrorExample Error-Response:
731+
* HTTP/1.1 500 Internal Server Error
732+
* {
733+
* "err": "Error while inserting in DB"
734+
* }
735+
*/
736+
675737
/**
676738
* @api {post} /module/add Add Module
677739
* @apiName AddModule
@@ -854,6 +916,20 @@
854916
* "err": "Error while inserting in DB"
855917
* }
856918
*/
919+
920+
/**
921+
* @api {delete} /attendance/delete/:attendanceId To delete Attendance
922+
* @apiName DeleteAttendance
923+
* @apiGroup Attendance
924+
*
925+
* @apiParam {String} attendanceId The ID of the attendance document to delete.
926+
*
927+
* @apiSuccess {String} res Success message indicating the deletion.
928+
*
929+
* @apiError (Error 500) err Error message if there was an error during the deletion.
930+
*
931+
* */
932+
857933
// ------------------------------------------------------------------------------------------
858934
// Practical.
859935
// ------------------------------------------------------------------------------------------
@@ -983,6 +1059,18 @@
9831059
* }
9841060
*/
9851061

1062+
/**
1063+
* @api {delete} /exam/delete/:id Delete Exam
1064+
* @apiName DeleteExam
1065+
* @apiExam Exam
1066+
*
1067+
* @apiParam {ObjectId} id The ObjectID of the exam to delete.
1068+
*
1069+
* @apiSuccess {String} res Success message indicating the deletion.
1070+
* @apiError (Error 500) ExamDeleteError Error while deleting the exam
1071+
*
1072+
*/
1073+
9861074
/**
9871075
* @api {delete} /assignment/delete/:assignmentId To delete Assignment
9881076
* @apiName DeleteAssignment
@@ -996,6 +1084,24 @@
9961084
*
9971085
* */
9981086

1087+
/**
1088+
* @api {post} /attendance/update update attendance details
1089+
* @apiName UpdateAttendance
1090+
* @apiGroup Attendance
1091+
* @apiDescription update Existing attendance
1092+
*
1093+
* @apiBody {String} [student] Student name.
1094+
* @apiBody {String} [course] Course name.
1095+
* @apiBody {Number} [monthlyAttended] Monthly attendance of student.
1096+
* @apiBody {Number} [monthlyOccured] Monthly occured.
1097+
* @apiBody {Number} [cumulativeAttended] sum of attendance of student.
1098+
* @apiBody {Number} [cumulativeOccured] sum of occured.
1099+
*
1100+
* @apiSuccess {String} res Attendance updated.
1101+
* @apiError (Error 500) err Error in updating database
1102+
*
1103+
*/
1104+
9991105
/**
10001106
* @api {post} /paper/update/:id Update Paper
10011107
* @apiName UpdatePaper
@@ -1034,6 +1140,42 @@
10341140
*
10351141
*/
10361142

1143+
/**
1144+
* @api {get} attendance/list Get Attendance List
1145+
* @apiName GetAttendance
1146+
* @apiGroup Attendance
1147+
*
1148+
* @apiBody {String} [student] Student name.
1149+
* @apiBody {String} [course] Course name.
1150+
* @apiBody {Number} [monthlyAttended] Monthly attendance of student.
1151+
* @apiBody {Number} [monthlyOccured] Monthly occured.
1152+
* @apiBody {Number} [cumulativeAttended] sum of attendance of student.
1153+
* @apiBody {Number} [cumulativeOccured] sum of occured.
1154+
*
1155+
* @apiSuccess {attendance[]} res Array of Filtered attendance Doc.
1156+
* @apiSuccess {String} attendance._id ID of document given by database.
1157+
* @apiSuccess {String} attendance.student Name of student.
1158+
* @apiSuccess {String} attendance.course Name of course.
1159+
* @apiSuccess {Number} attendance.monthlyAttended Monthly attendance of student.
1160+
* @apiSuccess {Number} attendance.cumulativeAttended sum of attendance of student.
1161+
* @apiSuccess {Number} attendance.cumulativeOccured sum of occured.
1162+
*/
1163+
1164+
/**
1165+
* @api {post} /exam/update/:id Update Exam Details
1166+
* @apiName UpdateExam
1167+
* @apiExam Exam
1168+
* @apiDescription Update existing exam details.
1169+
*
1170+
* @apiParam {ObjectId} id The ObjectID of the exam to update.
1171+
* @apiBody {String} [title] Exam title.
1172+
* @apiBody {ObjectId[]} [students] Array of student ObjectIDs.
1173+
*
1174+
* @apiSuccess {String} res Exam updated.
1175+
* @apiError (Error 500) ExamUpdateError Error in updating database
1176+
*
1177+
*/
1178+
10371179
/**
10381180
* @api {get} assignment/list Get Assignment List
10391181
* @apiName GetAssignment
@@ -1185,6 +1327,19 @@
11851327
*
11861328
*/
11871329

1330+
/**
1331+
* @api {get} /exam/list Get Exam List
1332+
* @apiName GetExamList
1333+
* @apiExam Exam
1334+
*
1335+
* @apiQuery {String} [title] Title of the exam.
1336+
*
1337+
* @apiSuccess {Exam[]} res Array of filtered exam documents.
1338+
* @apiSuccess {ObjectId} exam._id ObjectID of the exam document in the database.
1339+
* @apiSuccess {String} exam.title Title of the exam.
1340+
* @apiSuccess {ObjectId[]} exam.students Array of student ObjectIDs in the exam.
1341+
*/
1342+
11881343
/**
11891344
* @api {get} /group/list Get Group List
11901345
* @apiName GetGroupList
@@ -1516,6 +1671,7 @@
15161671
* @apiSuccess {String} res Topic updated.
15171672
* @apiError (Error 500) DatabaseError Error in updating the database.
15181673
*/
1674+
15191675
/**
15201676
* @api {post} /faculty/update/:id Update Faculty
15211677
* @apiName UpdateFaculty
@@ -1649,4 +1805,4 @@
16491805
* @apiSuccess {String} res topic updated.
16501806
* @apiError (Error 500) err Error in updating database
16511807
*
1652-
*/
1808+
*/

app.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import moduleRouter from "#routes/module";
2323
import facultyRouter from "#routes/faculty";
2424
import { identifyUser } from "#middleware/identifyUser";
2525
import departmentRouter from "#routes/department";
26+
import attendanceRouter from "#routes/attendance";
27+
import examRouter from "#routes/exam";
2628
import paperRouter from "#routes/paper";
2729
import groupRouter from "#routes/group";
2830
import performarouter from "#routes/performance";
@@ -60,6 +62,8 @@ app.use("/timetable", timetableRouter);
6062
app.use("/department", departmentRouter);
6163
app.use("/coursework", courseworkRouter);
6264
app.use("/module", moduleRouter);
65+
app.use("/attendance", attendanceRouter);
66+
app.use("/exam", examRouter);
6367
app.use("/paper", paperRouter);
6468
app.use("/group", groupRouter);
6569
app.use("/semester", semesterRouter);

controller/attendance.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {
2+
addNewAttendance, deleteAttendanceById, updateAttendanceById, getAttendances,
3+
} from "#services/attendance";
4+
import { logger } from "#util";
5+
6+
async function addAttendance(req, res) {
7+
const {
8+
student, course, monthlyAttended, monthlyOccured, cumulativeAttended, cumulativeOccured,
9+
} = req.body;
10+
try {
11+
// eslint-disable-next-line max-len
12+
const attendance = await addNewAttendance( student, course, monthlyAttended, monthlyOccured, cumulativeAttended, cumulativeOccured);
13+
res.json({ res: `added attendance ${attendance.student}`, id: attendance.id });
14+
} catch (error) {
15+
logger.error("Error while inserting", error);
16+
res.status(500);
17+
res.json({ err: "Error while inserting in DB" });
18+
}
19+
}
20+
async function deleteAttendance(req, res) {
21+
const { id } = req.params;
22+
try {
23+
await deleteAttendanceById(id);
24+
res.json({ res: "Attendance deleted successfully" });
25+
} catch (error) {
26+
logger.error("Error while deleting", error);
27+
res.status(500);
28+
res.json({ err: "Error while deleting from DB" });
29+
}
30+
}
31+
32+
async function updateAttendance(req, res) {
33+
const { id } = req.params;
34+
const {
35+
...data
36+
} = req.body;
37+
38+
try {
39+
await updateAttendanceById(id, data);
40+
res.json({ res: `${id} attendance updated` });
41+
} catch (error) {
42+
logger.error("Error while inserting", error);
43+
res.status(500);
44+
res.json({ err: "Error while inserting in DB" });
45+
}
46+
}
47+
48+
async function showAttendance(req, res) {
49+
try {
50+
const attendance = await getAttendances(req.query);
51+
return res.json({ res: attendance });
52+
} catch (error) {
53+
logger.error("Error while fetching", error);
54+
res.status(500);
55+
return res.json({ err: "Error while fetching the data" });
56+
}
57+
}
58+
59+
export default {
60+
addAttendance, updateAttendance, deleteAttendance, showAttendance,
61+
};
62+

controller/exam.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {
2+
createExam,
3+
deleteExamById,
4+
examList,
5+
updateExamById,
6+
} from "#services/exam";
7+
import { logger } from "#util";
8+
9+
async function addExam(req, res) {
10+
const {
11+
date, startTime, duration, infrastructure, supervisor, course,
12+
} = req.body;
13+
try {
14+
const exam = await createExam(
15+
date,
16+
startTime,
17+
duration,
18+
supervisor,
19+
infrastructure,
20+
course,
21+
);
22+
res.json({ res: `added exam ${exam.id}`, id: exam.id });
23+
} catch (error) {
24+
logger.error("Error while inserting", error);
25+
res.status(500);
26+
res.json({ err: "Error while inserting in DB" });
27+
}
28+
}
29+
30+
async function updateExam(req, res) {
31+
const { id } = req.params;
32+
const { ...data } = req.body;
33+
try {
34+
await updateExamById(id, data);
35+
res.json({ res: `updated exam with id ${id}` });
36+
} catch (error) {
37+
logger.error("Error while updating", error);
38+
res.status(500);
39+
res.json({ err: "Error while updaing in DB" });
40+
}
41+
}
42+
43+
async function getExam(req, res) {
44+
const filter = req.query;
45+
const exam = await examList(filter);
46+
res.json({ res: exam });
47+
}
48+
49+
async function deleteExam(req, res) {
50+
const { id } = req.params;
51+
try {
52+
await deleteExamById(id);
53+
res.json({ res: `Deleted exam with ID ${id}` });
54+
} catch (error) {
55+
logger.error("Error while deleting", error);
56+
res.status(500).json({ error: "Error while deleting from DB" });
57+
}
58+
}
59+
60+
export default {
61+
addExam,
62+
deleteExam,
63+
getExam,
64+
updateExam,
65+
};

0 commit comments

Comments
 (0)