From a81d2037cc242f2b234c68391866fecfb7a61008 Mon Sep 17 00:00:00 2001 From: Ankit Varshney Date: Sun, 26 Nov 2023 12:22:23 +0530 Subject: [PATCH 1/3] fix wallet payment --- controllers/payment_controller.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/payment_controller.js b/controllers/payment_controller.js index 4574185..35bcb2a 100644 --- a/controllers/payment_controller.js +++ b/controllers/payment_controller.js @@ -54,8 +54,10 @@ const paymentCtrl = { try { const user = req.user; const amount = parseInt(req.params.amount); - const result = amountSchema.validateAsync(amount) + console.log(amount) + const result = await amountSchema.validateAsync({amount}) const price = result.amount + console.log(price) if (user.cart.length == 0) { return next(new ErrorHandler(404, "No course in cart")); } @@ -156,7 +158,7 @@ const paymentCtrl = { try { // const user = req.user; const amount = parseInt(req.params.amount); - const result = amountSchema.validateAsync(amount) + const result =await amountSchema.validateAsync({amount}) const price = result.amount const razorpayInstance = new Razorpay({ key_id: process.env.KEY_ID, @@ -189,7 +191,7 @@ const paymentCtrl = { checkPayment: async (req, res, next) => { try { const amount = parseInt(req.params.amount); - const result =amountSchema.validateAsync(amount) + const result =await amountSchema.validateAsync({amount}) const price = result.amount const user = req.user; From d6616292a0f6403d4cf6b3984379184f81ee3c5f Mon Sep 17 00:00:00 2001 From: Ankit Varshney Date: Sun, 26 Nov 2023 12:28:28 +0530 Subject: [PATCH 2/3] added reivews in response --- controllers/course_controller.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/controllers/course_controller.js b/controllers/course_controller.js index dff5da5..2abe57f 100644 --- a/controllers/course_controller.js +++ b/controllers/course_controller.js @@ -96,7 +96,7 @@ const courseCtrl = { const course = await Course.findById(courseId, { isPublished: true, isPublished: 0, - reviews: 0, + __v: 0, ratings: 0, }) @@ -122,13 +122,14 @@ const courseCtrl = { const courseIdIndex = user.ownedCourse.findIndex((course) => course.courseId.equals(courseId) ); + const cartIdIndex = user.cart.findIndex((course) => course.equals(courseId) ); const wishlistIdIndex = user.wishlist.findIndex((course) => course.equals(courseId) ); - + if (cartIdIndex != -1) { in_cart = true; } @@ -215,6 +216,7 @@ const courseCtrl = { duration: 1, totalStudents: 1, category: 1, + weightedRating:1, rating: 1, thumbnail: 1, createdAt: 1, @@ -289,7 +291,7 @@ const courseCtrl = { .populate({ path: "courses", select: - "_id title description category price thumbnail rating duration createdAt updatedAt ", + "_id title description category price thumbnail rating weightedRating duration createdAt updatedAt ", options: { limit: limit ? limit : pageSize, }, From bf50e9e2a3e1d1e5a1b01f7503a721a329c9d7aa Mon Sep 17 00:00:00 2001 From: Ankit Varshney Date: Sun, 26 Nov 2023 12:31:26 +0530 Subject: [PATCH 3/3] populated reviews --- controllers/course_controller.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/controllers/course_controller.js b/controllers/course_controller.js index 2abe57f..5db0f10 100644 --- a/controllers/course_controller.js +++ b/controllers/course_controller.js @@ -96,7 +96,7 @@ const courseCtrl = { const course = await Course.findById(courseId, { isPublished: true, isPublished: 0, - + __v: 0, ratings: 0, }) @@ -113,6 +113,10 @@ const courseCtrl = { path: "preview", select: "_id videoTitle videoUrl videoDuration videoUrl_144p videoUrl_360p videoUrl_720p", + }) + .populate({ + path: "reviews.user", + select: "_id username name profileimg", }); if (!course) { @@ -129,7 +133,7 @@ const courseCtrl = { const wishlistIdIndex = user.wishlist.findIndex((course) => course.equals(courseId) ); - + if (cartIdIndex != -1) { in_cart = true; } @@ -216,7 +220,7 @@ const courseCtrl = { duration: 1, totalStudents: 1, category: 1, - weightedRating:1, + weightedRating: 1, rating: 1, thumbnail: 1, createdAt: 1, @@ -325,7 +329,7 @@ const courseCtrl = { .sort({ count: -1 }) .select({ search: 1, _id: 0 }) .limit(5); - + res.json({ success: true, message: "List of popular searches", @@ -456,7 +460,7 @@ const courseCtrl = { thumbnail: 1, createdAt: 1, updatedAt: 1, - weightedRating:1, + weightedRating: 1, createdBy: { _id: 1, username: 1, name: 1 }, }, },