diff --git a/controllers/course_controller.js b/controllers/course_controller.js index 5db0f10..da4fc9e 100644 --- a/controllers/course_controller.js +++ b/controllers/course_controller.js @@ -122,6 +122,13 @@ const courseCtrl = { if (!course) { return next(new ErrorHandler(400, "No course found")); } + await PopularSearch.findOneAndUpdate( + { + search: course.title, + }, + { $inc: { count: 1 } }, + { upsert: true } + ); const user = req.user; const courseIdIndex = user.ownedCourse.findIndex((course) => course.courseId.equals(courseId) @@ -349,13 +356,7 @@ const courseCtrl = { const startIndex = (page - 1) * pageSize; const searchquery = req.query.coursetitle; - await PopularSearch.findOneAndUpdate( - { - search: searchquery, - }, - { $inc: { count: 1 } }, - { upsert: true } - ); + const result = await Course.aggregate([ { $search: { diff --git a/controllers/payment_controller.js b/controllers/payment_controller.js index 35bcb2a..508bdd1 100644 --- a/controllers/payment_controller.js +++ b/controllers/payment_controller.js @@ -15,6 +15,9 @@ const paymentCtrl = { if (!course) { return next(new ErrorHandler(400, "No course found")); } + if (course.isPublished == false) { + return next(new ErrorHandler(400, "Course is not published")); + } const courseIdIndex = user.ownedCourse.findIndex((course) => course.courseId.equals(courseId) );