diff --git a/models/cart.js b/models/cart.js new file mode 100644 index 0000000..f4096fa --- /dev/null +++ b/models/cart.js @@ -0,0 +1,13 @@ +const mongoose = require('mongoose') +const cartSchema = new mongoose.Schema({ + userId: { + type: mongoose.Schema.Types.ObjectId, + ref: "User", + }, + courseId:{ + type: mongoose.Schema.Types.ObjectId, + ref: "Course", + } +}) +const cart = new mongoose.model("cart", cartSchema) +module.exports = cart; diff --git a/models/category.js b/models/category.js index b9e93c8..8cbd1e1 100644 --- a/models/category.js +++ b/models/category.js @@ -4,14 +4,14 @@ const categorySchema = new mongoose.Schema({ name: { type: String, required: true, - unique: true, + // unique: true, }, - courses: [ + courses: { type: mongoose.Schema.Types.ObjectId, ref: "Course", }, - ], + }); const Category = new mongoose.model("Category", categorySchema); module.exports = Category; diff --git a/models/completedCourse.js b/models/completedCourse.js new file mode 100644 index 0000000..5515cc6 --- /dev/null +++ b/models/completedCourse.js @@ -0,0 +1,14 @@ +const mongoose = require("mongoose") +const completedCourseSchema = new mongoose.Schema({ + userId: { + type: mongoose.Schema.Types.ObjectId, + ref: "User", + + }, + courseId: { + type: mongoose.Schema.Types.ObjectId, + ref: "Course", + }, +}) +const completedCourse = new mongoose.model("completedCourse", completedCourseSchema) +module.exports = completedCourse; \ No newline at end of file diff --git a/models/completedVideo.js b/models/completedVideo.js new file mode 100644 index 0000000..5f08b76 --- /dev/null +++ b/models/completedVideo.js @@ -0,0 +1,19 @@ +const mongoose = require("mongoose") +const completedVideoSchema = new mongoose.Schema({ + userId: { + type: mongoose.Schema.Types.ObjectId, + ref: "User", + + }, + courseId: { + type: mongoose.Schema.Types.ObjectId, + ref: "Course", + + }, + videoId: { + type: mongoose.Schema.Types.ObjectId, + ref: "Video", + }, +}) +const completedVideo = new mongoose.model("completedVideo", completedVideoSchema) +module.exports = completedVideo; \ No newline at end of file diff --git a/models/course.js b/models/course.js index c3eca7c..5807f9b 100644 --- a/models/course.js +++ b/models/course.js @@ -1,6 +1,6 @@ const mongoose = require("mongoose"); -const reviewSchema = require("./review"); +// const reviewSchema = require("./review"); const courseSchema = new mongoose.Schema( { title: { @@ -20,17 +20,17 @@ const courseSchema = new mongoose.Schema( ref: "User", }, - videos: [ - { - video: { - type: mongoose.Schema.Types.ObjectId, - ref: "Video", - }, - note: { - type: String, - }, - }, - ], + // videos: [ + // { + // video: { + // type: mongoose.Schema.Types.ObjectId, + // ref: "Video", + // }, + // note: { + // type: String, + // }, + // }, + // ], category: { type: String, @@ -62,17 +62,17 @@ const courseSchema = new mongoose.Schema( type: Number, default: 0, }, - preview: [ + preview: { type: mongoose.Schema.Types.ObjectId, ref: "Video", }, - ], + isPublished: { type: Boolean, default: false, }, - reviews: [reviewSchema], + // reviews: [reviewSchema], weightedRating: { type: Number, default: 0, diff --git a/models/createdCourse.js b/models/createdCourse.js new file mode 100644 index 0000000..6994629 --- /dev/null +++ b/models/createdCourse.js @@ -0,0 +1,14 @@ +const mongoose = require("mongoose") +const createdCoursesSchema = new mongoose.Schema({ + userId: { + type: mongoose.Schema.Types.ObjectId, + ref: "User", + }, + courseId: { + type: mongoose.Schema.Types.ObjectId, + ref: "Course", + }, + +}) +const createdCourse = new mongoose.model("createdCourse", createdCoursesSchema) +module.exports = createdCourse; \ No newline at end of file diff --git a/models/ownedCourse.js b/models/ownedCourse.js new file mode 100644 index 0000000..686d9a0 --- /dev/null +++ b/models/ownedCourse.js @@ -0,0 +1,19 @@ +const mongoose = require("mongoose"); +const ownedCoursesSchema = new mongoose.Schema({ + courseId: { + type: mongoose.Schema.Types.ObjectId, + ref: "Course", + }, + completedVideo: [ + { + type: mongoose.Schema.Types.ObjectId, + ref: "Video", + }, + ], + + userId: { + type: mongoose.Schema.Types.ObjectId, + ref: "User", + }, +}); +const ownedCourse = new mongoose.model("ownedCourse", ownedCoursesSchema); diff --git a/models/review.js b/models/review.js index 92c27ee..2c1f946 100644 --- a/models/review.js +++ b/models/review.js @@ -1,6 +1,10 @@ const mongoose = require("mongoose"); const reviewSchema = new mongoose.Schema( { + courseId: { + type: mongoose.Schema.Types.ObjectId, + ref: "Course", + }, user: { type: mongoose.Schema.Types.ObjectId, ref: "User", diff --git a/models/user_model.js b/models/user_model.js index 5e8b613..7376ed4 100644 --- a/models/user_model.js +++ b/models/user_model.js @@ -39,44 +39,44 @@ const userSchema = new mongoose.Schema({ profileimg: { type: String, }, - createdCourse: [ - { - type: mongoose.Schema.Types.ObjectId, - ref: "Course", - }, - ], - ownedCourse: [ - { - courseId: { - type: mongoose.Schema.Types.ObjectId, - ref: "Course", - }, - completedVideo: [ - { - type: mongoose.Schema.Types.ObjectId, - ref: "Video", - }, - ], - }, - ], - cart: [ - { - type: mongoose.Schema.Types.ObjectId, - ref: "Course", - }, - ], - wishlist: [ - { - type: mongoose.Schema.Types.ObjectId, - ref: "Course", - }, - ], - completedCourse: [ - { - type: mongoose.Schema.Types.ObjectId, - ref: "Course", - }, - ], + // createdCourse: [ + // { + // type: mongoose.Schema.Types.ObjectId, + // ref: "Course", + // }, + // ], + // ownedCourse: [ + // { + // courseId: { + // type: mongoose.Schema.Types.ObjectId, + // ref: "Course", + // }, + // completedVideo: [ + // { + // type: mongoose.Schema.Types.ObjectId, + // ref: "Video", + // }, + // ], + // }, + // ], + // cart: [ + // { + // type: mongoose.Schema.Types.ObjectId, + // ref: "Course", + // }, + // ], + // wishlist: [ + // { + // type: mongoose.Schema.Types.ObjectId, + // ref: "Course", + // }, + // ], + // completedCourse: [ + // { + // type: mongoose.Schema.Types.ObjectId, + // ref: "Course", + // }, + // ], wallet: { type: Number, default: 0, @@ -90,8 +90,8 @@ const userSchema = new mongoose.Schema({ default: false, }, }); -userSchema.path("createdCourse").default(() => []); -userSchema.path("ownedCourse").default(() => []); +// userSchema.path("createdCourse").default(() => []); +// userSchema.path("ownedCourse").default(() => []); const User = new mongoose.model("User", userSchema); module.exports = User; diff --git a/models/video.js b/models/video.js index 70a2a74..7aa8a46 100644 --- a/models/video.js +++ b/models/video.js @@ -1,6 +1,11 @@ const mongoose = require("mongoose"); const videoSchema = new mongoose.Schema({ + courseId: { + type: mongoose.Schema.Types.ObjectId, + ref: "Course", + }, + videoTitle: { type: String, required: true, @@ -22,6 +27,9 @@ const videoSchema = new mongoose.Schema({ type: Number, required: true, }, + note: { + type:String + } }); const Video = new mongoose.model("Video", videoSchema); module.exports = Video; diff --git a/models/wishlist.js b/models/wishlist.js new file mode 100644 index 0000000..e69de29