forked from greylockhackfest/07.21.2012
-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.js
52 lines (46 loc) · 1.85 KB
/
models.js
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
module.exports = (function () {
var mongoose = require('mongoose');
var Schema = mongoose.Schema,
ObjectId = Schema.ObjectId,
models = {};
var UserSchema = new Schema({
name: String,
password: { type: String, required: true },
email: { type: String, required: true, lowercase: true, trim: true },
assignments: [{ type: ObjectId, ref: 'Assignment' }],
});
models.User = mongoose.model('User', UserSchema);
var CommentSchema = new Schema({
text: { type: String, required: true },
user: { type: ObjectId, ref: 'User', required: true } ,
timestamp: { type: Date, required: true },
startLine: { type: Number, required: true },
endLine: { type: Number, required: true },
});
models.Comment = mongoose.model('Comment', CommentSchema);
var FileSchema = new Schema({
name: { type: String, required: true },
slug: { type: String },
path: { type: String, required: true },
timestamp: { type: Date, required: true },
comments: [{ type: ObjectId, ref: 'Comment' }]
});
models.File = mongoose.model('File', FileSchema);
var CourseSchema = new Schema({
name: { type: String, required: true },
slug: { type: String, unique: true },
staff: [{ type: ObjectId, ref: 'User', required: true }],
students: [{ type: ObjectId, ref: 'User' }],
assignments: [String]
});
models.Course = mongoose.model('Course', CourseSchema);
var AssignmentSchema = new Schema({
name: { type: String },
slug: { type: String },
course: { type: ObjectId, ref: 'Course', required: true },
user: { type: ObjectId, ref: 'User', required: true },
files: [{ type: ObjectId, ref: 'File' }]
});
models.Assignment = mongoose.model('Assignment', AssignmentSchema);
return models;
})();