-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.js
58 lines (53 loc) · 1.74 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
53
54
55
56
57
58
var cfg = require('konphyg')(__dirname + '/public/config');
var configdata = cfg('config');
var mongoose = require('mongoose');
var db = mongoose.createConnection(configdata.db);
var ObjectId = mongoose.Schema.Types.ObjectId;
// Assigning models to the global namespace for now. This should make DB related stuff convenient.
// FIXME: Revisit this later - its against node convention and in the future we could split models into several files.
GLOBAL.Class = db.model('Class', mongoose.Schema ({
dept : String,
num : String,
type : String,
subnum : Number,
name : String,
ccn : {type: Number, unique: true, index: true}
}));
GLOBAL.User = db.model('User', mongoose.Schema ({
fbId: {type: Number, unique: true, index: true },
email: String,
password: String,
name: String,
first_name: String,
link: String,
picture: String,
access_token: String,
classes: [{ type: ObjectId, ref: 'Class' }],
hasSignedUp: { type: Boolean, default: false },
seshs : [{type: ObjectId, ref: 'Sesh'}]
}));
GLOBAL.SessionComment = db.model('SessionComment', mongoose.Schema ({
created: Date,
author: { type: ObjectId, ref: 'User' },
text: String
}));
GLOBAL.Sesh = db.model('Sesh', mongoose.Schema ({
time: Date,
loc: {
x : Number,
y : Number
},
course: { type: ObjectId, ref: 'Class' },
description : String,
title : String,
comments: [SessionComment],
users: [{ type: ObjectId, ref: 'User' }],
created : Date
}));
GLOBAL.Notification = db.model('Notification', mongoose.Schema ({
created: Date,
source: { type: ObjectId, ref: 'User' },
text: String,
ref: { type: ObjectId, ref: 'Session' },
users: [{ type: Number, ref: 'User' }]
}));