Skip to content

Commit

Permalink
Merge branch 'TechNodes2-0:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Satuti99 authored Jun 19, 2024
2 parents 6ce399b + f50d04c commit 5f184ae
Show file tree
Hide file tree
Showing 7 changed files with 515 additions and 455 deletions.
64 changes: 64 additions & 0 deletions server/Controllers/FeedbackController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const Feedback = require("../Models/FeedbackModel");
const { ElectiveSubject } = require("../Models/StudentModel");
const { Student } = require("../Models/StudentModel");
exports.addFeedback = async (req, res) => {
try {
const { electiveSubjectId, studentId, reviews } = req.body;
console.log(electiveSubjectId, studentId, reviews);
if (!electiveSubjectId || !studentId || !reviews) {
return res
.status(400)
.json({ error: "Please provide all the required fields" });
}
const student = await Student.findById(studentId);
const electiveSubject = await ElectiveSubject.findById(electiveSubjectId);
if (!student || !electiveSubject) {
return res
.status(404)
.json({ error: "Student or Elective subject not found" });
}
const feedback = new Feedback({
student: student._id,
electiveSubject: electiveSubject._id,
reviews,
});
const savedFeedback = await feedback.save();
res.json(savedFeedback);
} catch (error) {
console.log(error);
res.status(500).json({ error: "Internal server error" });
}
};

exports.getFeedback = async (req, res) => {
try {
let { subjectCode } = req.params;
if (!subjectCode) {
return res
.status(400)
.json({ error: "Please provide the Elective Subject Id" });
}
subjectCode = subjectCode.split(":")[1];
console.log(subjectCode);
const subject = await ElectiveSubject.findOne(
{ subjectCode: subjectCode },
"_id"
);

console.log(subject);
if (!subject) {
return res.status(404).json({
error:
"Subject Not Found! Please provide a valid Elective Subject Code",
});
}
// console.log(subject._id);
const feedbacks = await Feedback.find({
electiveSubject: subject._id,
}).populate("student");
res.json(feedbacks);
} catch (error) {
console.log(error);
res.status(500).json({ error: "Internal server error" });
}
};
Loading

0 comments on commit 5f184ae

Please sign in to comment.