Skip to content

Commit 4b7eb45

Browse files
authored
Update attendance.js
1 parent 4f171f8 commit 4b7eb45

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

controller/attendance.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
getAttendances,
66
} from "#services/attendance";
77
import { logger } from "#util";
8+
import { isEntityIdValid } from "#middleware/entityIdValidation";
9+
import Student from "#models/attendance";
10+
import Course from "#models/course";
811

912
async function addAttendance(req, res) {
1013
const {
@@ -15,8 +18,15 @@ async function addAttendance(req, res) {
1518
cumulativeAttended,
1619
cumulativeOccured,
1720
} = req.body;
21+
const isStudentValid = await isEntityIdValid(student, Student);
22+
const isCourseValid = await isEntityIdValid(course, Course);
1823
try {
1924
// eslint-disable-next-line max-len
25+
if (!isStudentValid || !isCourseValid) {
26+
res.status(400).json({
27+
error: "Invalid Id",
28+
});
29+
}
2030
const attendance = await addNewAttendance(
2131
student,
2232
course,

0 commit comments

Comments
 (0)