-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema.js
108 lines (100 loc) · 3.09 KB
/
schema.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
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
/* vim: set ts=2: */
// There are three collections: Users, Schools, and Notes.
//
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
var RATING_MAX = 100;
var RATING_MIN = 0;
//====== USERS ====================================
// Action values are taken from this array:
var ReputationEvents = [
{ descr: "contribute a note", value: 15, icon: "<char>" },
{}
];
// The descr and value properties have values which come
// from some element of the ReputationEvents array. The
// author is the user who instigated the ReputationEvent;
// this user if null;
var ReputationEventSchema = new Schema ({
desc : String,
value : Number,
authorID : Schema.ObjectId,
timestamp : Date
});
var NoteDescriptionSchema = new Schema ({
title : String,
field : String,
desc : String,
NoteID : Schema.ObjectId
}); // Attention... this is meant to display all of a user's downlaods and uploads... see userschema below.
var UserSchema = new Schema({
name : String,
schoolID : Schema.ObjectId,
otherSchool : String,
gradYear : String,
email : String,
facebookid : String,
notesUp : [NoteDescriptionSchema], // displayed on the profile page - notes uploaded by a user
notesDown : [NoteDescriptionSchema], // displayed on the profile page - notes downloaded by a user
karmas : [ReputationEventSchema],
privileges : {
canUpload : Boolean,
canRead : Boolean,
canVote : Boolean,
canComment : Boolean,
canModerate : Boolean
},
noteIDs : [Schema.ObjectId],
tags : [String]
});
//===== SCHOOLS ===================================
var NoteDesc = new Schema({
id: Schema.ObjectId,
noteDesc: String
});
var fields = [
"English",
"Computer Science"
];
// The value of the field property must be taken from the
// fields array.
var CourseSchema = new Schema({
title : String,
professor : String,
field : { type: String, enum: fields },
acadYear : String,
daysOfWk : String, // e.g., MoWeFr optional field
hour : String, // optionl field
notes : [NoteDesc],
tags : [String]
});
var SchoolSchema = new Schema({
name : String,
location : String,
url : String,
courses : [CourseSchema],
tags : [String],
hostnames : [String] // e.g., alumni.upenn.edu
});
//===== NOTES ====================================
var VoteSchema = new Schema({
user : Schema.ObjectId,
upordown : String
});
var NoteSchema = new Schema({
contributorID : Schema.ObjectId,
field : { type: String, enum: fields },
desc : String,
origfiletype : String,
origfilebytes : Number,
origfilecontent : String,
htmlcontent : String,
viewCount : Number, // number of views of the HTML content of a given Note.
votes : [VoteSchema],
tags : [String]
});
var User = mongoose.model( 'User', UserSchema );
var School = mongoose.model( 'School', SchoolSchema );
var Note = mongoose.model( 'Note', NoteSchema );
module.exports.mongoose = mongoose;
// should we export User, School, and Note?