forked from Deen-Bridge/dnb-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.js
More file actions
98 lines (94 loc) · 2.12 KB
/
Copy pathCourse.js
File metadata and controls
98 lines (94 loc) · 2.12 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
import mongoose from "mongoose";
import { getSupportedCodes } from "../config/assets.js";
const courseSchema = new mongoose.Schema(
{
title: {
type: String,
required: true,
trim: true,
},
description: {
type: String,
required: true,
},
category: {
type: String,
required: true,
},
thumbnail: {
type: String, // image URL
},
video: {
type: String, // video URL or playlist ID
},
price: {
type: Number,
default: 0,
},
currency: {
type: String,
default: "USDC",
enum: getSupportedCodes(),
},
rating: {
type: Number,
default: 0,
min: 0,
max: 5,
},
numReviews: {
type: Number,
default: 0,
min: 0,
},
ratingBreakdown: {
1: { type: Number, default: 0 },
2: { type: Number, default: 0 },
3: { type: Number, default: 0 },
4: { type: Number, default: 0 },
5: { type: Number, default: 0 },
},
reviews: [
{
user: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
},
comment: { type: String, required: true },
rating: {
type: Number,
required: true,
min: 1,
max: 5,
validate: { validator: Number.isInteger, message: "Rating must be an integer" },
},
createdAt: { type: Date, default: Date.now },
},
],
createdBy: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
required: true,
},
enrolledUsers: [{ type: mongoose.Schema.Types.ObjectId, ref: "User" }],
sections: [
{
title: String,
order: Number,
lessons: [
{
title: String,
order: Number,
videoUrl: String,
durationSeconds: Number,
},
],
},
],
},
{ timestamps: true }
);
courseSchema.index({ title: "text", description: "text", category: "text" }, { weights: { title: 5 } });
courseSchema.index({ rating: -1 });
export default mongoose.model("Course", courseSchema);