Skip to content

Commit

Permalink
removed array and created new relationships in database
Browse files Browse the repository at this point in the history
  • Loading branch information
AVtheking committed Nov 28, 2023
1 parent 7ee4ad0 commit 4cfd69c
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 58 deletions.
13 changes: 13 additions & 0 deletions models/cart.js
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 3 additions & 3 deletions models/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 14 additions & 0 deletions models/completedCourse.js
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 19 additions & 0 deletions models/completedVideo.js
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 15 additions & 15 deletions models/course.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mongoose = require("mongoose");

const reviewSchema = require("./review");
// const reviewSchema = require("./review");
const courseSchema = new mongoose.Schema(
{
title: {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions models/createdCourse.js
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 19 additions & 0 deletions models/ownedCourse.js
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 4 additions & 0 deletions models/review.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
80 changes: 40 additions & 40 deletions models/user_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
8 changes: 8 additions & 0 deletions models/video.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
Empty file added models/wishlist.js
Empty file.

0 comments on commit 4cfd69c

Please sign in to comment.