-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.js
107 lines (86 loc) · 2.38 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
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
var mongoose = require('mongoose');
var autoIncrement = require('mongoose-auto-increment');
var uristring =
process.env.MONGOLAB_URI ||
process.env.MONGOHQ_URL ||
'mongodb://localhost/test';
mongoose.connect(uristring);
var db = mongoose.connection;
autoIncrement.initialize(db);
db.on('error', function (err) {
console.log("Error: " + err);
});
var userSchema = mongoose.Schema({
first_name: String,
last_name: String,
email: String,
auth_token: String,
school_id: { type: Number, ref: 'School' },
facebook: {
id: Number,
token: String
},
phone_number: Number,
groups: [{type: Number, ref: 'Group'}],
intensity: String,
image: String,
created_at: Date
});
userSchema.plugin(autoIncrement.plugin, 'User');
var schoolSchema = mongoose.Schema({
name: String,
domain: String,
courses: [{type: Number, ref: 'Course'}]
});
schoolSchema.plugin(autoIncrement.plugin, 'School');
var courseSchema = mongoose.Schema({
school_id: {type: Number, ref: 'School'},
name: String,
term: String,
instructor: String,
groups: [{type: Number, ref: 'Group'}],
created_at: Date
});
courseSchema.plugin(autoIncrement.plugin, 'Course');
var groupSchema = mongoose.Schema({
name: String,
course_id: {type: Number, ref: 'Course'},
intensity: String,
motto: String,
entry_question: String,
description: String,
open: Boolean,
next_meeting: Date,
created_at: Date,
hidden: Boolean,
users: [{type: Number, ref: 'User'}],
topics: [{type: Number, ref: 'Topic'}],
requests: [{type: Number, ref: "Request"}]
});
groupSchema.plugin(autoIncrement.plugin, 'Group');
var topicSchema = mongoose.Schema({
group_id: {type: Number, ref: 'Group'},
title: String,
topic_date: Date,
updated_at: Date,
flashcards: [],
pads: []
});
topicSchema.plugin(autoIncrement.plugin, 'Topic');
var requestSchema = mongoose.Schema({
group_id: {type: Number, ref: 'Group'},
user_id: {type: Number, ref: 'User'},
entry_answer: String,
ignored: Boolean,
created_at: Date
});
requestSchema.plugin(autoIncrement.plugin, 'Request');
var self = module.exports = {
db: db,
User: mongoose.model('User', userSchema),
School: mongoose.model('School', schoolSchema),
Course: mongoose.model('Course', courseSchema),
Group: mongoose.model('Group', groupSchema),
Topic: mongoose.model('Topic', topicSchema),
Request: mongoose.model('Request', requestSchema)
};