From 2c5728482626823c268f01f5604cc4f453ece4a1 Mon Sep 17 00:00:00 2001
From: Oitash
Date: Tue, 5 Nov 2024 01:11:54 +0530
Subject: [PATCH] :hammer: Working....
---
server/controllers/Payments.js | 6 ++++--
server/controllers/Profile.js | 2 +-
server/routes/Profile.js | 1 +
.../core/Dashboard/InstructorDashboard/Instructor.jsx | 5 +++++
src/services/operations/profileAPI.js | 4 +++-
5 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/server/controllers/Payments.js b/server/controllers/Payments.js
index 5b75b71..e6d0c3c 100644
--- a/server/controllers/Payments.js
+++ b/server/controllers/Payments.js
@@ -150,7 +150,7 @@ const enrollStudents = async (courses, userId, res) => {
// Find the course and enroll the student in it
const enrolledCourse = await Course.findOneAndUpdate(
{ _id: courseId },
- { $push: { studentsEnroled: userId } },
+ { $push: { studentsEnrolled: userId } },
{ new: true }
)
@@ -180,6 +180,7 @@ const enrollStudents = async (courses, userId, res) => {
)
console.log("Enrolled student: ", enrolledStudent)
+
// Send an email notification to the enrolled student
const emailResponse = await mailSender(
enrolledStudent.email,
@@ -191,7 +192,8 @@ const enrollStudents = async (courses, userId, res) => {
)
console.log("Email sent successfully: ", emailResponse.response)
- } catch (error) {
+ }
+ catch (error) {
console.log(error)
return res.status(400).json({ success: false, error: error.message })
}
diff --git a/server/controllers/Profile.js b/server/controllers/Profile.js
index edc8b63..39ad60d 100644
--- a/server/controllers/Profile.js
+++ b/server/controllers/Profile.js
@@ -228,7 +228,7 @@ exports.instructorDashboard = async (req, res) => {
const courseDetails = await Course.find({ instructor: req.user.id })
const courseData = courseDetails.map((course) => {
- const totalStudentsEnrolled = course.studentsEnroled.length
+ const totalStudentsEnrolled = course.studentsEnrolled.length
const totalAmountGenerated = totalStudentsEnrolled * course.price
// Create a new object with the additional fields
diff --git a/server/routes/Profile.js b/server/routes/Profile.js
index 55952fd..6638193 100644
--- a/server/routes/Profile.js
+++ b/server/routes/Profile.js
@@ -17,6 +17,7 @@ const {
router.delete("/deleteProfile", auth, deleteAccount)
router.put("/updateProfile", auth, updateProfile)
router.get("/getUserDetails", auth, getAllUserDetails)
+
// Get Enrolled Courses
router.get("/getEnrolledCourses", auth, getEnrolledCourses)
router.put("/updateDisplayPicture", auth, updateDisplayPicture)
diff --git a/src/components/core/Dashboard/InstructorDashboard/Instructor.jsx b/src/components/core/Dashboard/InstructorDashboard/Instructor.jsx
index 1a693b4..5f9886a 100644
--- a/src/components/core/Dashboard/InstructorDashboard/Instructor.jsx
+++ b/src/components/core/Dashboard/InstructorDashboard/Instructor.jsx
@@ -16,6 +16,7 @@ const Instructor = () => {
useEffect(() => {
;(async () => {
setLoading(true)
+
const instructorApiData = await getInstructorData(token)
const result = await fetchInstructorCourses(token)
console.log("Instructor API data->", instructorApiData)
@@ -44,10 +45,12 @@ const Instructor = () => {
Hi {user?.firstName} 👋
+
Let's start something new
+
{loading ? (
) : courses.length > 0 ? (
@@ -64,6 +67,7 @@ const Instructor = () => {
)}
+
{/* Total Statistics */}
Statistics
@@ -90,6 +94,7 @@ const Instructor = () => {
+
{/* Render 3 courses */}
Your Courses
diff --git a/src/services/operations/profileAPI.js b/src/services/operations/profileAPI.js
index 4336ca2..63d773a 100644
--- a/src/services/operations/profileAPI.js
+++ b/src/services/operations/profileAPI.js
@@ -73,6 +73,7 @@ export async function getUserEnrolledCourses(token) {
export async function getInstructorData(token) {
const toastId = toast.loading("Loading...");
let result = [];
+
try {
const response = await apiConnector("GET", GET_INSTRUCTOR_DATA_API, null, {
Authorization: `Bearer ${token}`,
@@ -80,7 +81,8 @@ export async function getInstructorData(token) {
console.log("GET_INSTRUCTOR_API_RESPONSE", response);
result = response?.data?.courses;
- } catch (error) {
+ }
+ catch (error) {
console.log("GET_INSTRUCTOR_API ERROR", error);
toast.error("Could not Get Instructor Data");
}