Repository navigation
Expand file tree
/
Copy pathCourse.model.js
More file actions
203 lines (197 loc) · 3.47 KB
/
Copy pathCourse.model.js
File metadata and controls
203 lines (197 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
const mongoose = require('mongoose');
// Quiz schema for course assessments
const quizSchema = new mongoose.Schema({
title: {
type: String,
required: true
},
questions: [{
_id: {
type: mongoose.Schema.Types.ObjectId,
auto: true
},
questionText: {
type: String,
required: true
},
questionType: {
type: String,
enum: ['multiple-choice', 'true-false', 'short-answer'],
required: true
},
options: [String], // For multiple choice and true/false
correctAnswer: {
type: String,
required: true
},
points: {
type: Number,
default: 1
}
}],
passingScore: {
type: Number,
default: 70,
min: 0,
max: 100
},
timeLimit: {
type: Number, // in minutes
default: null
}
}, { _id: false });
// Lesson schema
const lessonSchema = new mongoose.Schema({
_id: {
type: mongoose.Schema.Types.ObjectId,
auto: true
},
title: {
type: String,
required: true
},
description: {
type: String,
default: ''
},
content: {
type: String, // Markdown or HTML content
default: ''
},
videoUrl: {
type: String,
default: ''
},
resources: [{
name: String,
url: String,
type: {
type: String,
enum: ['pdf', 'link', 'document', 'other'],
default: 'link'
}
}],
quiz: quizSchema,
duration: {
type: Number, // in minutes
default: 0
},
order: {
type: Number,
required: true
}
}, { _id: false });
// Module schema
const moduleSchema = new mongoose.Schema({
_id: {
type: mongoose.Schema.Types.ObjectId,
auto: true
},
title: {
type: String,
required: true
},
description: {
type: String,
default: ''
},
lessons: [lessonSchema],
order: {
type: Number,
required: true
}
}, { _id: false });
const courseSchema = new mongoose.Schema({
title: {
type: String,
required: true
},
description: {
type: String,
required: true
},
thumbnail: {
type: String,
default: ''
},
thumbnail_public_id: {
type: String,
default: ''
},
instructor: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
category: {
type: String,
required: true
},
tags: [{
type: String
}],
duration: {
type: Number, // in minutes, calculated from lessons
default: 0
},
level: {
type: String,
enum: ['beginner', 'intermediate', 'advanced'],
default: 'beginner'
},
isFree: {
type: Boolean,
default: true
},
price: {
type: Number,
default: 0
},
modules: [moduleSchema],
description_short: {
type: String,
default: ''
},
learningOutcomes: [{
type: String
}],
requirements: [{
type: String
}],
enrollmentCount: {
type: Number,
default: 0
},
averageRating: {
type: Number,
default: 0,
min: 0,
max: 5
},
ratingCount: {
type: Number,
default: 0
},
isPublished: {
type: Boolean,
default: false
},
status: {
type: String,
enum: ['draft', 'published', 'archived'],
default: 'draft'
},
certificateTemplate: {
type: String,
default: '' // Can store certificate design or ID
}
}, {
timestamps: true
});
// Indexes
courseSchema.index({ instructor: 1 });
courseSchema.index({ category: 1 });
courseSchema.index({ tags: 1 });
courseSchema.index({ isPublished: 1 });
courseSchema.index({ createdAt: -1 });
module.exports = mongoose.model('Course', courseSchema);