Skip to content

Commit 1037407

Browse files
committed
tested All Routes except ratingandreview,coursePurchase,enrollment , Payments Routes
1 parent 8a91e9a commit 1037407

19 files changed

+313
-113
lines changed

SERVER/config/cloudinary.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const cloudinary=require("cloudinary").v2;
2+
exports.cloudinaryConnect=()=>{
3+
try {
4+
cloudinary.config({
5+
//configure cloudinary to upload edia
6+
cloud_name:process.env.CLOUD_NAME,
7+
api_key:process.env.API_KEY,
8+
api_secret:process.env.API_SECRET,
9+
})
10+
}
11+
catch (error) {
12+
13+
}
14+
}

SERVER/config/database.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ require('dotenv').config();
33

44

55
exports.Dbconnect=()=>{
6-
mongoose.connect(process.env.MONGODB_URL,{
7-
useNewUrlParser:true,
8-
useUnifiedTopology:true
9-
})
6+
mongoose.connect(process.env.MONGODB_URL)
107
.then(()=>console.log("Db connected successfully"))
118
.catch((error)=>{
12-
console.log("error ehile connecting database")
13-
console.error(error);
9+
console.log("error while connecting database")
10+
console.log(error);
1411
process.exit(1);
1512
})
1613
}

SERVER/controllers/Auth.controller.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ exports.signUp=async(req,res)=>{
9292
otp,
9393
}=req.body;
9494
//validate data
95-
if(!firstName || !lastName || !email || !password || !confirmPassword || !otp || !contactNumber ) {
95+
if(!firstName || !lastName || !email || !password || !confirmPassword || !otp ) {
9696
return res.status(403).json({
9797
success:false,
9898
message:'all fields are required',
@@ -123,7 +123,7 @@ exports.signUp=async(req,res)=>{
123123
//OTP not Found
124124
return res.status(400).json({
125125
success:false,
126-
message:"OTP Found"
126+
message:"OTP Is Not found"
127127
})
128128
}
129129
else if(otp !==recentOtp[0].otp){
@@ -182,9 +182,9 @@ exports.signUp=async(req,res)=>{
182182
exports.login=async(req,res)=>{
183183
try {
184184
//get data from req body
185-
const {email,passowrd}=req.body;
185+
const {email,password}=req.body;
186186
//validation of data
187-
if(!email || !passowrd){
187+
if(!email || !password){
188188
return res.status(403).json({
189189
success:false,
190190
message:" all fileds are required please try again"
@@ -203,7 +203,7 @@ exports.login=async(req,res)=>{
203203
}
204204
// Generate JWT token and Compare Password
205205

206-
if(await bcrypt.compare(passowrd,user.password)) {
206+
if(await bcrypt.compare(password,user.password)) {
207207
const payload= {
208208
email:user.email,
209209
id:user._id,

SERVER/controllers/Category.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Category = require("../models/Category");
1+
const Category = require("../models/Category.model");
22

33
exports.createCategory = async (req, res) => {
44
try {

SERVER/controllers/Course.controller.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Course=require('../models/Course.model');
22
const Category=require('../models/Category.model');
33
const User= require('../models/User.model');
44
const {uploadImageToCloudinary}=require('../utils/imageUploader');
5+
const RatingAndReview=require("../models/RatingAndReviews.model")
56

67
require('dotenv').config()
78

@@ -58,12 +59,12 @@ exports.createCourse=async(req,res)=>{
5859
}
5960

6061
//check given tag valid or not
61-
const categoryDetails= await Category.findById(tag);
62+
const categoryDetails= await Category.findById(category);
6263

6364
if(!categoryDetails){
6465
return res.status(404).json({
6566
success:false,
66-
message:"Tag Details not foundCategory Details Not Found",
67+
message:"Tag Details not found Category Details Not Found",
6768
})
6869
}
6970

@@ -179,14 +180,14 @@ exports.getCourseDetails=async(req,res)=>{
179180
}
180181
)
181182
.populate("category")
182-
.populate("ratingAndreviews")
183-
.populate(
184-
{
185-
path:"courseContent",
186-
populate:{
187-
path:"subSection"
188-
}
189-
})
183+
// .populate("RatingAndreviews")
184+
.populate("courseContent.subSection")
185+
// {
186+
// path:"courseContent",
187+
// populate:{
188+
// path:"subSection"
189+
// }
190+
// })
190191
.exec();
191192

192193
//validation

SERVER/controllers/Payments.controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { instance } = require("../config/razorpay");
22
const Course = require("../models/Course.model");
33
const User = require("../models/User.model");
4-
const { courseEnrollmentEmail } = require("../utils/templates/courseEnrollmentEmail");
4+
const { courseEnrollmentEmail } = require("../mail/templates/courseEnrollmentEmail");
55
const mailSender = require("../utils/mailSender");
66
const mongoose = require("mongoose");
77

SERVER/controllers/Profile.controller.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Profile= require("../models/Profile.model");
22
const User= require("../models/User.model");
3+
const {uploadImageToCloudinary}=require("../utils/imageUploader")
34

45
exports.updateProfile=async(req,res)=>{
56
try {
@@ -50,6 +51,7 @@ exports.updateProfile=async(req,res)=>{
5051
exports.deleteAccount=async(req,res)=>{
5152
try {
5253
//get Id
54+
console.log(req.user)
5355
const id = req.user.id;
5456
//validation
5557
const userDetails= await User.findById({_id:id});
@@ -110,32 +112,32 @@ exports.getAllUserDetails=async(req,res)=>{
110112
}
111113

112114
exports.updateDisplayPicture = async (req, res) => {
113-
try {
114-
const displayPicture = req.files.displayPicture
115-
const userId = req.user.id
116-
const image = await uploadImageToCloudinary(
117-
displayPicture,
118-
process.env.FOLDER_NAME,
119-
1000,
120-
1000
121-
)
122-
console.log(image)
123-
const updatedProfile = await User.findByIdAndUpdate(
124-
{ _id: userId },
125-
{ image: image.secure_url },
126-
{ new: true }
127-
)
128-
res.send({
129-
success: true,
130-
message: `Image Updated successfully`,
131-
data: updatedProfile,
132-
})
133-
} catch (error) {
134-
return res.status(500).json({
135-
success: false,
136-
message: error.message,
137-
})
138-
}
115+
try {
116+
const displayPicture = req.files.displayPicture
117+
const userId = req.user.id
118+
const image = await uploadImageToCloudinary(
119+
displayPicture,
120+
process.env.FOLDER_NAME,
121+
1000,
122+
1000
123+
)
124+
console.log(image)
125+
const updatedProfile = await User.findByIdAndUpdate(
126+
{ _id: userId },
127+
{ image: image.secure_url },
128+
{ new: true }
129+
)
130+
res.send({
131+
success: true,
132+
message: `Image Updated successfully`,
133+
data: updatedProfile,
134+
})
135+
} catch (error) {
136+
return res.status(500).json({
137+
success: false,
138+
message: error.message,
139+
})
140+
}
139141
};
140142

141143
exports.getEnrolledCourses = async (req, res) => {

SERVER/controllers/ResetPassword.controller.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
const User= require('../models/User.model');
22
const mailSender= require('../utils/mailSender')
3-
const bcrypt= require('bcrypt')
3+
const bcrypt= require('bcrypt');
4+
const crypto=require("crypto")
45

56

67
//reset password token
78
exports.resetPasswordToken= async(req,res)=>{
89
try {
910
//get email from req body
10-
const {email}=req.body.email;
11+
const {email}=req.body;
1112

1213
//check user for this email, email validation
1314
const user = await User.findOne({email:email});
@@ -24,19 +25,19 @@ exports.resetPasswordToken= async(req,res)=>{
2425
{email:email},
2526
{
2627
token:token,
27-
resetPasswordExpires:Date.now() + 3600000,
28+
resetPasswordExpires:Date.now()+3*60*60*1000,
2829
},
2930
{new: true},
3031

3132
)
3233
console.log("Details",updatedDetailes);
3334
//create url
34-
const url=`http//localhost:3000/update-password/${token}`
35+
const url=`http//localhost:4000/update-password/${token}`
3536
// send mail containing urll
3637
await mailSender(
3738
email,
38-
"password Reset Link",
39-
`Your Link for email verification is ${url}. Please click this url to reset your password.`
39+
"password Reset Link",
40+
`Your Link for email verification is ${url} . Please click this url to reset your password.`
4041
)
4142
// return Response
4243
return res.status(200).json({
@@ -80,7 +81,7 @@ exports.resetPassword=async(req,res)=>{
8081
})
8182
}
8283
//token time check
83-
if(userdetails.resetPasswordExpires > Date.now()){
84+
if(userdetails.resetPasswordExpires < Date.now()){
8485
return res.status(403).json({
8586
success: false,
8687
message: `Token is Expired, Please Regenerate Your Token`
@@ -89,7 +90,7 @@ exports.resetPassword=async(req,res)=>{
8990
// hash password
9091
const hashedPassword= await bcrypt.hash(password,10);
9192
//update password
92-
await User.findOneAndUpdat(
93+
await User.findOneAndUpdate(
9394
{token:token},
9495
{password:hashedPassword},
9596
{new:true},

SERVER/controllers/Section.controller.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const Section = require("../models/Section.model");
22
const Course = require("../models/Course.model")
33

4+
45
exports.createSection=async(req,res)=>{
56
try {
67
// Extract the required properties from the request body
@@ -25,12 +26,13 @@ exports.createSection=async(req,res)=>{
2526
},
2627
{new:true},
2728
)
28-
.populate({
29-
path: "courseContent",
30-
populate: {
31-
path: "subSection",
32-
},
33-
})
29+
.populate("courseContent.Section")
30+
// .populate({
31+
// path: "courseContent",
32+
// populate: {
33+
// path: "subSection",
34+
// },
35+
// })
3436
.exec();
3537

3638
// Return the updated course object in the response
@@ -59,12 +61,15 @@ exports.updateSection=async(req,res)=>{
5961
if(!sectionName || !SectionId){
6062
return res.status(400).json({
6163
success:false,
62-
message:"missing alll properties"
64+
message:"missing all properties"
6365
})
6466
}
67+
68+
6569
//update data
6670
const section= await Section.findByIdAndUpdate(SectionId,{sectionName},{new:true})
6771
//return response
72+
// console.error("Error deleting section:", error);
6873
return res.status(200).json({
6974
success:true,
7075
message:section,
@@ -86,13 +91,14 @@ exports.updateSection=async(req,res)=>{
8691
exports.deleteSection=async(req,res)=>{
8792
try {
8893
//data fetch section Id
89-
const {SectionId}= req.params
94+
const {SectionId}= req.body;
9095
//use findbyidanddelete
91-
const deletedSection= await Section.findByIdAndDelete(SectionId,)
96+
const deletedSection= await Section.findByIdAndDelete(SectionId)
9297
//return response
9398
return res.status(200).json({
9499
success:true,
95-
message :"section deleted successfully"
100+
message :"section deleted successfully",
101+
data:deletedSection,
96102
})
97103
}
98104
catch (error) {

SERVER/controllers/Subsection.controller.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const SubSection = require("../models/SubSection.model");
22
const Section = require("../models/Section.model");
3-
const uploadImageToCloudinary = require("../utils/imageUploader")
3+
const {uploadImageToCloudinary} = require("../utils/imageUploader")
44

55

66
// Create a new sub-section for a given section
@@ -22,7 +22,7 @@ exports.createSubSection = async (req, res) => {
2222
})
2323
}
2424
//upload video to cloudinary
25-
const uploadvideo = await uploadImageToCloudinary(video, process.env.FOLDER_NAME)
25+
const uploadvideo = await uploadImageToCloudinary(video, process.env.FOLDER_NAME);
2626
//create subsection
2727
const SubSectionDetails = await SubSection.create({
2828
title: title,
@@ -33,13 +33,9 @@ exports.createSubSection = async (req, res) => {
3333
// Update the corresponding section with the newly created sub-section
3434
const updatedSection = await Section.findByIdAndUpdate(
3535
{ _id: sectionId },
36-
{
37-
$push: {
38-
subsection: SubSectionDetails._id,
39-
}
40-
},
36+
{ $push: { subSection: SubSectionDetails._id } },
4137
{ new: true }
42-
).populate("subSection")
38+
).populate("subSection")
4339

4440

4541
// Return the updated section in the response

0 commit comments

Comments
 (0)