-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpages.js
154 lines (144 loc) · 6.27 KB
/
pages.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
var models = require('./models');
var utils = require('./utils');
app.get('/', utils.isLoggedIn, function(req, res) {
models.Group.find({_id: {$in: app.get('user').groups}})
.populate('users')
.exec(function(err, groups) {
res.render('groups/groups.jade', {
user: app.get('name'),
image: app.get('user').image,
groups: JSON.stringify(groups),
user_token: app.get('user').facebook.token,
user_id: app.get('user')._id
});
});
});
app.get('/users/:user_id/edit', utils.isLoggedIn, utils.isUser, function(req, res) {
models.School.find().exec(function(err, schools) {
res.render('users/edit_user.jade', {
schools: JSON.stringify(schools),
user: app.get('name'),
image: app.get('user').image,
user_obj: app.get('user'),
user_id: app.get('user')._id
});
});
});
app.get('/groups/new', utils.isLoggedIn, function(req, res) {
models.Course.find({ school_id: app.get('user').school_id })
.exec(function(err, courses){
res.render('groups/create-group.jade', {
user: app.get('name'),
image: app.get('user').image,
courses: JSON.stringify(courses),
user_token: app.get('user').facebook.token,
user_id: app.get('user')._id
});
});
});
app.get('/groups/search', utils.isLoggedIn, function(req, res) {
models.Group.find({hidden: false})
.populate('users course_id')
.exec(function(err, groups) {
res.render('groups/find-group.jade', {
user: app.get('name'),
user_id: app.get('user')._id,
image: app.get('user').image,
user_groups: req.user.groups,
groups: JSON.stringify(groups),
user_token: app.get('user').facebook.token,
user_id: app.get('user')._id
});
});
});
app.get('/join_group', utils.isLoggedIn, function(req, res) {
models.Group.findOne({_id: req.query['group_id']}).exec(function(err, group) {
res.render('groups/join-group.jade', {
user: app.get('name'),
image: app.get('user').image,
group: group,
user_token: app.get('user').facebook.token,
user_id: app.get('user')._id
});
});
});
app.get('/groups/:group_id/requests', utils.isLoggedIn, utils.isGroupMember, function(req, res) {
models.Request.find({group_id: req.params.group_id, ignored: false})
.populate('user_id group_id')
.exec(function(err, requests) {
res.render('groups/requests.jade', {
user: app.get('name'),
image: app.get('user').image,
requests: JSON.stringify(requests),
user_token: app.get('user').facebook.token,
user_id: app.get('user')._id
});
});
});
app.get('/groups/:group_id/flashcards', utils.isLoggedIn, utils.isGroupMember, function(req, res){
models.Group.findOne({_id: req.params.group_id})
.populate('topics')
.exec(function(err, group){
if (group === null) {
res.send(404, 'Group does not exist.');
} else {
res.render('topics/topics.jade', {
user: app.get('name'),
image: app.get('user').image,
group_name: group.name,
group_id: group._id,
topics: JSON.stringify(group.topics),
user_token: app.get('user').facebook.token,
user_id: app.get('user')._id
});
}
});
});
app.get('/groups/:group_id/flashcards/:topic_id', utils.isLoggedIn, utils.isGroupMember, function(req, res){
models.Topic.findOne({_id: req.params.topic_id})
.populate('group_id')
.exec(function(err, topic){
res.render('flashcards/flashcards.jade', {
user: app.get('name'),
image: app.get('user').image,
group_name: topic.group_id.name,
group_id: topic.group_id._id,
topic: JSON.stringify(topic),
flashcards: JSON.stringify(topic.flashcards),
user_token: app.get('user').facebook.token,
user_id: app.get('user')._id
});
});
});
app.get('/groups/:group_id/flashcards/:topic_id/edit', utils.isLoggedIn, utils.isGroupMember, function(req, res) {
models.Topic.findOne({_id: req.params.topic_id})
.populate('group_id')
.exec(function(err, topic) {
res.render('flashcards/edit_flashcards.jade', {
user: app.get('name'),
image: app.get('user').image,
group_name: topic.group_id.name,
topic: JSON.stringify(topic),
flashcards: JSON.stringify(topic.flashcards),
pads: JSON.stringify(topic.pads),
user_token: app.get('user').facebook.token,
user_id: app.get('user')._id
});
});
});
app.get('/groups/:group_id/edit', utils.isLoggedIn, utils.isGroupMember, function(req, res) {
models.Course.find({ school_id: app.get('user').school_id })
.exec(function(err, courses){
models.Group.findOne({_id: req.params.group_id})
.exec(function(err, group){
res.render('groups/edit-group.jade', {
user: app.get('name'),
image: app.get('user').image,
group: JSON.stringify(group),
user_token: app.get('user').facebook.token,
user_id: app.get('user')._id,
courses: JSON.stringify(courses)
});
});
});
});