Skip to content

Commit

Permalink
🔨 Developing...
Browse files Browse the repository at this point in the history
  • Loading branch information
oitashg committed Nov 27, 2024
1 parent 235bbc7 commit 6733963
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 8 deletions.
51 changes: 49 additions & 2 deletions server/controllers/Course.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/pages/Catalog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ const Catalog = () => {
if (!loading && !catalogPageData.success) {
return <Error />
}


console.log("Catalog page data -> ", catalogPageData)

return (
<>
{/* Hero Section */}
Expand Down Expand Up @@ -109,6 +111,7 @@ const Catalog = () => {
/>
</div>
</div>

{/* Section 2 */}
<div className=" mx-auto box-content w-full max-w-maxContentTab px-4 py-12 lg:max-w-maxContent">
<div className="section_heading">
Expand All @@ -123,7 +126,7 @@ const Catalog = () => {

{/* Section 3 */}
<div className=" mx-auto box-content w-full max-w-maxContentTab px-4 py-12 lg:max-w-maxContent">
<div className="section_heading">Frequently Bought</div>
<div className="section_heading text-white">Frequently Bought</div>
<div className="py-8">
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
{catalogPageData?.data?.mostSellingCourses
Expand All @@ -134,7 +137,7 @@ const Catalog = () => {
</div>
</div>
</div>

<Footer />
</>
)
Expand Down
7 changes: 4 additions & 3 deletions src/pages/CourseDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ const CourseDetails = () => {
const [avgReviewCount, setAvgReviewCount] = useState(0)

useEffect(() => {
const count = GetAvgRating(response?.data?.courseDetails.ratingAndReviews)
const count = GetAvgRating(response?.data?.courseDetails[0].ratingAndReviews)
setAvgReviewCount(count)
}, [response])
// console.log("avgReviewCount: ", avgReviewCount)

// // Collapse all
console.log("avgReviewCount: ", avgReviewCount)

// Collapse all
// const [collapse, setCollapse] = useState("")
const [isActive, setIsActive] = useState(Array(0))
const handleActive = (id) => {
Expand Down

0 comments on commit 6733963

Please sign in to comment.