From 6733963ed6701dcd93877cd9b570fde666388e7b Mon Sep 17 00:00:00 2001 From: Oitash Date: Wed, 27 Nov 2024 11:27:09 +0530 Subject: [PATCH] :hammer: Developing... --- server/controllers/Course.js | 51 ++++++++++++++++++++++++++++++++++-- src/pages/Catalog.jsx | 9 ++++--- src/pages/CourseDetails.jsx | 7 ++--- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/server/controllers/Course.js b/server/controllers/Course.js index dcba816..216660c 100644 --- a/server/controllers/Course.js +++ b/server/controllers/Course.js @@ -4,6 +4,7 @@ const User = require("../models/User") const Section = require("../models/Section") const SubSection = require("../models/SubSection") const CourseProgress = require("../models/CourseProgress") +const RatingAndReview = require("../models/RatingAndReview") const {uploadImageToCloudinary} = require("../utils/imageUploader") const {convertSecondsToDuration} = require("../utils/secToDuration") @@ -425,8 +426,7 @@ exports.getInstructorCourses = async (req, res) => { // Delete the Course exports.deleteCourse = async (req, res) => { try { - const {courseId } = req.body - + const {courseId} = req.body console.log("Course Id -> ", courseId) // Find the course @@ -496,6 +496,53 @@ exports.deleteCourse = async (req, res) => { console.log("Category Id -> ", categoryId) console.log("Upated category details -> ", updatedCategory) + + //Delete the ratingReview entry also while deleting the course + const ratingReviewId = course.ratingAndReviews + console.log("Rating Reviw Id -> ", ratingReviewId) + await RatingAndReview.findByIdAndDelete(ratingReviewId) + + //Delete the courseProgress of all students enrolled in this course while deleting the course + const enrolledStudentDetails = course.studentsEnrolled + console.log("Enrolled Students detail -> ", enrolledStudentDetails) + + for(const studentId of enrolledStudentDetails){ + //string details of each user + const userDetails = await User.findById(studentId) + .populate("courseProgress") + .exec() + + //extracting courseProgress details of each user + const courseProgressDetails = userDetails.courseProgress + console.log("Course Progress Details -> ", courseProgressDetails) + + //storing the particular courseProgressId of the course of this student + let courseProgressId + for(const element of courseProgressDetails){ + if(element.courseID == courseId){ + courseProgressId = element._id + break + } + } + + console.log("CourseProgress Id -> ", courseProgressId) + + const updatedCourseProgress = await User.findByIdAndUpdate( + studentId, + { + $pull: { + courseProgress: courseProgressId + } + }, + {new: true}) + .populate("courseProgress") + .exec() + + console.log("Updated courseProgress -> ", updatedCourseProgress) + + //Delete the courseprogress of that student for this course + await CourseProgress.findByIdAndDelete(courseProgressId) + } // Delete the course await Course.findByIdAndDelete(courseId) diff --git a/src/pages/Catalog.jsx b/src/pages/Catalog.jsx index ae36f61..cfd9ab5 100644 --- a/src/pages/Catalog.jsx +++ b/src/pages/Catalog.jsx @@ -57,7 +57,9 @@ const Catalog = () => { if (!loading && !catalogPageData.success) { return } - + + console.log("Catalog page data -> ", catalogPageData) + return ( <> {/* Hero Section */} @@ -109,6 +111,7 @@ const Catalog = () => { /> + {/* Section 2 */}
@@ -123,7 +126,7 @@ const Catalog = () => { {/* Section 3 */}
-
Frequently Bought
+
Frequently Bought
{catalogPageData?.data?.mostSellingCourses @@ -134,7 +137,7 @@ const Catalog = () => {
- +