diff --git a/server/controllers/Category.js b/server/controllers/Category.js index e9692de..a0f6b60 100644 --- a/server/controllers/Category.js +++ b/server/controllers/Category.js @@ -99,9 +99,13 @@ exports.categoryPageDetails = async(req, res) => { { //we are finding those courses whose id is not equal($ne) to current category id _id: {$ne: categoryId} + }, + {new: true}) + .populate({ + path: "courses", + populate: "ratingAndReviews" }) - // .populate("courses") - // .exec() + .exec() let differentCategory = await Category.findOne( differentCategories[getRandomInt(differentCategories.length)] @@ -110,6 +114,9 @@ exports.categoryPageDetails = async(req, res) => { .populate({ path: "courses", match: { status: "Published" }, + populate: { + path: "ratingAndReviews" + } }) .exec() @@ -122,6 +129,7 @@ exports.categoryPageDetails = async(req, res) => { match: { status: "Published" }, populate: { path: "instructor", + path: "ratingAndReviews" }, }) .exec() @@ -140,6 +148,7 @@ exports.categoryPageDetails = async(req, res) => { data: { selectedCategory, differentCategories, + differentCategory, mostSellingCourses, } }) diff --git a/server/controllers/Course.js b/server/controllers/Course.js index b8371ef..05ed066 100644 --- a/server/controllers/Course.js +++ b/server/controllers/Course.js @@ -254,7 +254,7 @@ exports.getCourseDetails = async(req, res) => { //find course details(we don't want object ID..so populate everything) const courseDetails = await Course.find( - //searcing parameter + //searching parameter {_id: courseId}, {new: true}) .populate({ @@ -269,12 +269,11 @@ exports.getCourseDetails = async(req, res) => { .populate("createdAt") .populate("whatYouWillLearn") .populate("thumbnail") + .populate("instructions") .populate("price") .populate({ path: "studentsEnrolled", - populate: { - path: "additionalDetails" - } + select: "_id" }) .populate("ratingAndReviews") .populate({ @@ -362,12 +361,12 @@ exports.getFullCourseDetails = async (req, res) => { }) } - if (courseDetails.status === "Draft") { - return res.status(403).json({ - success: false, - message: `Accessing a draft course is forbidden`, - }); - } + // if (courseDetails.status === "Draft") { + // return res.status(403).json({ + // success: false, + // message: `Accessing a draft course is forbidden`, + // }); + // } let totalDurationInSeconds = 0 courseDetails.courseContent.forEach((content) => { diff --git a/server/controllers/Profile.js b/server/controllers/Profile.js index 39ad60d..7dc979e 100644 --- a/server/controllers/Profile.js +++ b/server/controllers/Profile.js @@ -11,7 +11,7 @@ exports.updateProfile = async(req, res) => { try{ //get the data - const {dateOfBirth = "", about = "", contactNumber, gender} = req.body + const {firstName, lastName, dateOfBirth = "", about = "", contactNumber, gender} = req.body //get the userID const id = req.user.id @@ -39,17 +39,26 @@ exports.updateProfile = async(req, res) => { //Another way to update the values in database..i.e..by save //When object already present(here profileDetails) then use save //First one was by create...here no object was created + userDetails.firstName = firstName + userDetails.lastName = lastName profileDetails.dateOfBirth = dateOfBirth profileDetails.about = about profileDetails.gender = gender profileDetails.contactNumber = contactNumber + await userDetails.save() await profileDetails.save() + const finalUserDetails = await User.findByIdAndUpdate( + id, + {new: true}) + .populate("additionalDetails") + .exec() + //return response return res.status(200).json({ success: true, message: "Profile updated successfully", - profileDetails + finalUserDetails }) } catch(error){ @@ -140,14 +149,16 @@ exports.updateDisplayPicture = async (req, res) => { ) console.log(image) const updatedProfile = await User.findByIdAndUpdate( - { _id: userId }, + userId, { image: image.secure_url }, - { new: true } - ) + { new: true }) + .populate("additionalDetails") + .exec() + res.send({ success: true, message: `Image Updated successfully`, - data: updatedProfile, + updatedProfile, }) } catch (error) { return res.status(500).json({ diff --git a/src/App.js b/src/App.js index e915a87..a69160e 100644 --- a/src/App.js +++ b/src/App.js @@ -119,7 +119,7 @@ function App() { user?.accountType === ACCOUNT_TYPE.STUDENT && ( <> }/> - }/> + {/* }/> */} ) } diff --git a/src/components/common/Navbar.jsx b/src/components/common/Navbar.jsx index 47c9ec8..35426a9 100644 --- a/src/components/common/Navbar.jsx +++ b/src/components/common/Navbar.jsx @@ -123,7 +123,7 @@ const Navbar = () => {
{/* Cart Symbol */} - { + {/* { user && user?.accountType !== "Instructor" && ( @@ -136,7 +136,7 @@ const Navbar = () => { } ) - } + } */} {/* Log in button */} {/* token is null means user is not logged in */} diff --git a/src/components/core/Catalog/Course_Card.jsx b/src/components/core/Catalog/Course_Card.jsx index fc1c73c..fc1cec0 100644 --- a/src/components/core/Catalog/Course_Card.jsx +++ b/src/components/core/Catalog/Course_Card.jsx @@ -7,17 +7,12 @@ const Course_Card = ({course, Height}) => { const [avgReviewCount, setAvgReviewCount] = useState(0); console.log("Course in course card -> ", course) - console.log("Course rating in course card -> ", course.ratingAndReviews) useEffect(()=> { const count = GetAvgRating(course?.ratingAndReviews); - console.log("Count -> ", count) setAvgReviewCount(count); - console.log("Count 1-> ", avgReviewCount) },[course]) - console.log("Count 2-> ", avgReviewCount) - return ( <> diff --git a/src/components/core/Course/CourseDetailsCard.js b/src/components/core/Course/CourseDetailsCard.js index e255fd4..b629108 100644 --- a/src/components/core/Course/CourseDetailsCard.js +++ b/src/components/core/Course/CourseDetailsCard.js @@ -21,6 +21,20 @@ const CourseDetailsCard = ({course, setConfirmationModal, handleBuyCourse}) => { _id: courseId, } = course[0] + console.log("Course -> ", course) + console.log("User -> ", user) + + let isEnrolled = false + + for(const id of course[0]?.studentsEnrolled){ + if(id._id == user?._id){ + isEnrolled = true + break + } + } + + console.log("Isenrolled -> ", isEnrolled) + const handleShare = () => { copy(window.location.href) toast.success("Link copied to clipboard") @@ -45,7 +59,7 @@ const CourseDetailsCard = ({course, setConfirmationModal, handleBuyCourse}) => { }) } - // console.log("Student already enrolled ", course?.studentsEnrolled, user?._id) + console.log("Student already enrolled ", course[0]?.studentsEnrolled?.includes(user?._id)) return ( <> @@ -55,7 +69,7 @@ const CourseDetailsCard = ({course, setConfirmationModal, handleBuyCourse}) => { {/* Course Image */} {course?.courseName} @@ -67,20 +81,21 @@ const CourseDetailsCard = ({course, setConfirmationModal, handleBuyCourse}) => { - {(!user || !course?.studentsEnrolled?.includes(user?._id)) && ( + {/* {(!user || !course?.studentsEnrolled?.includes(user?._id)) && ( - )} + )} */}

@@ -93,7 +108,7 @@ const CourseDetailsCard = ({course, setConfirmationModal, handleBuyCourse}) => { This Course Includes :

- {course?.instructions?.map((item, i) => { + {course[0]?.instructions?.map((item, i) => { return (

diff --git a/src/components/core/Dashboard/Cart/RenderCartCourses.jsx b/src/components/core/Dashboard/Cart/RenderCartCourses.jsx index 4837ae3..08d0c49 100644 --- a/src/components/core/Dashboard/Cart/RenderCartCourses.jsx +++ b/src/components/core/Dashboard/Cart/RenderCartCourses.jsx @@ -36,7 +36,7 @@ const RenderCartCourses = () => { {course?.category?.name}

- 4.5 + {course?.ratingAndReviews} { + const { user } = useSelector((state) => state.profile); + const navigate = useNavigate(); - const {user} = useSelector((state) => state.profile) - const navigate = useNavigate() + console.log("User in My profile-> ", user); - console.log("User -> ", user) - return (
-

- My Profile -

+

+ My Profile +

- {/* Section 1 */} -
-
- {`profile-${user?.firstName}`} -
-

- {user?.firstName + " " + user?.lastName} -

- -

- {user?.email} -

-
-
+ {/* Section 1 */} +
+
+ {`profile-${user?.firstName}`} +
+

+ {user?.firstName + " " + user?.lastName} +

- { - navigate("/dashboard/settings") - }} - > - - +

{user?.email}

+
- {/* Section 2 */} -
-
-

About

- { - navigate("/dashboard/settings") - }} - > - - -
-

- {user?.additionalDetails?.about ?? "Write Something About Yourself"} -

-
+ { + navigate("/dashboard/settings"); + }} + > + + +
+ {/* Section 2 */} +
+
+

About

+ { + navigate("/dashboard/settings"); + }} + > + + +
+

+ {user?.additionalDetails?.about ?? "Write Something About Yourself"} +

+
+ + {/* Section 3 */}
+ {/* Personal details and Button */}

Personal Details @@ -78,14 +78,15 @@ const MyProfile = () => { { - navigate("/dashboard/settings") + navigate("/dashboard/settings"); }} >

- +
+ {/* Left side */}

First Name

@@ -93,12 +94,14 @@ const MyProfile = () => { {user?.firstName}

+

Email

{user?.email}

+

Gender

@@ -106,6 +109,8 @@ const MyProfile = () => {

+ + {/* Right side */}

Last Name

@@ -113,12 +118,14 @@ const MyProfile = () => { {user?.lastName}

+

Phone Number

{user?.additionalDetails?.contactNumber ?? "Add Contact Number"}

+

Date Of Birth

@@ -129,8 +136,9 @@ const MyProfile = () => {

+
- ) -} + ); +}; -export default MyProfile +export default MyProfile; diff --git a/src/components/core/Dashboard/Settings/EditProfile.jsx b/src/components/core/Dashboard/Settings/EditProfile.jsx index cec1200..8578ca3 100644 --- a/src/components/core/Dashboard/Settings/EditProfile.jsx +++ b/src/components/core/Dashboard/Settings/EditProfile.jsx @@ -24,6 +24,7 @@ const EditProfile = () => { console.log("Form Data while submitting the form-> ", data) try { dispatch(updateProfile(token, data)) + console.log("Form Data after submitting the form-> ", data) } catch (error) { console.log("ERROR MESSAGE - ", error.message) diff --git a/src/data/dashboard-links.js b/src/data/dashboard-links.js index c384b0e..665251a 100644 --- a/src/data/dashboard-links.js +++ b/src/data/dashboard-links.js @@ -35,11 +35,11 @@ export const sidebarLinks = [ type: ACCOUNT_TYPE.STUDENT, icon: "VscMortarBoard", }, - { - id: 6, - name: "Your Cart", - path: "/dashboard/cart", - type: ACCOUNT_TYPE.STUDENT, - icon: "VscHistory", - }, + // { + // id: 6, + // name: "Your Cart", + // path: "/dashboard/cart", + // type: ACCOUNT_TYPE.STUDENT, + // icon: "VscHistory", + // }, ]; diff --git a/src/pages/Catalog.jsx b/src/pages/Catalog.jsx index 9626bb8..246f45c 100644 --- a/src/pages/Catalog.jsx +++ b/src/pages/Catalog.jsx @@ -12,7 +12,7 @@ import CourseSlider from '../components/core/Catalog/CourseSlider' const Catalog = () => { const { loading } = useSelector((state) => state.profile) - const { catalogName } = useParams() + const { catalogName } = useParams() //extract from the link const [active, setActive] = useState(1) const [catalogPageData, setCatalogPageData] = useState(null); const [categoryId, setCategoryId] = useState(""); @@ -119,7 +119,7 @@ const Catalog = () => {
diff --git a/src/pages/CourseDetails.jsx b/src/pages/CourseDetails.jsx index eeab654..132ce6c 100644 --- a/src/pages/CourseDetails.jsx +++ b/src/pages/CourseDetails.jsx @@ -33,7 +33,7 @@ const CourseDetails = () => { const [confirmationModal, setConfirmationModal] = useState(null) useEffect(() => { - // Calling fetchCourseDetails fucntion to fetch the details + // Calling fetchCourseDetails function to fetch the details ;(async () => { try { const res = await fetchCourseDetails(courseId) @@ -103,6 +103,7 @@ const CourseDetails = () => { _id: course_id, courseContent, ratingAndReviews, + instructions, instructor, studentsEnrolled, createdAt, diff --git a/src/services/operations/SettingsAPI.js b/src/services/operations/SettingsAPI.js index 4bd6c81..bd3e9cd 100644 --- a/src/services/operations/SettingsAPI.js +++ b/src/services/operations/SettingsAPI.js @@ -35,7 +35,7 @@ const { throw new Error(response.data.message) } toast.success("Display Picture Updated Successfully") - dispatch(setUser(response.data.data)) + dispatch(setUser(response.data.updatedProfile)) } catch (error) { console.log("UPDATE_DISPLAY_PICTURE_API API ERROR............", error) @@ -48,6 +48,8 @@ const { export function updateProfile(token, formData) { return async (dispatch) => { const toastId = toast.loading("Loading...") + + console.log("Formdata in settings API before -> ", formData) try { const response = await apiConnector("PUT", UPDATE_PROFILE_API, formData, { @@ -59,12 +61,14 @@ const { if (!response.data.success) { throw new Error(response.data.message) } - const userImage = response.data.profileDetails?.image - ? response.data.profileDetails?.image - : `https://api.dicebear.com/5.x/initials/svg?seed=${formData?.firstName} ${formData?.lastName}` + const userImage = response.data.finalUserDetails?.image + ? response.data.finalUserDetails?.image + : `https://api.dicebear.com/5.x/initials/svg?seed=${response.data.finalUserDetails?.firstName}${response.data.finalUserDetails?.lastName}` dispatch( - setUser({ ...response.data.profileDetails, image: userImage }) + setUser({...response.data.finalUserDetails, image: userImage}) ) + // localStorage.setItem("user", JSON.stringify(response.data.userDetails)) + console.log("User image ->", userImage) toast.success("Profile Updated Successfully") } diff --git a/src/utils/avgRating.js b/src/utils/avgRating.js index 84bf517..143b151 100644 --- a/src/utils/avgRating.js +++ b/src/utils/avgRating.js @@ -4,7 +4,9 @@ export default function GetAvgRating(ratingArr) { acc += curr.rating return acc }, 0) - + + console.log("Total review count -> ", totalReviewCount) + const multiplier = Math.pow(10, 1) const avgReviewCount = Math.round((totalReviewCount / ratingArr?.length) * multiplier) / multiplier