-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-PostManTesting.js
152 lines (135 loc) · 4.14 KB
/
app-PostManTesting.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
var express = require('express');
var mongoose = require('mongoose');
var models = require('./models/models');
var bodyParser = require('body-parser');
var path = require('path');
var connect = process.env.MONGODB_URI || require('./models/connect');
// var userConnectionMethods = require('userConnection')
mongoose.connect(connect);
var app = express();
app.set('views', path.join(__dirname, 'views'));
var hbs = require('express-handlebars')({
defaultLayout: 'layout',
extname: '.hbs'
});
app.engine('hbs', hbs);
app.set('view engine', 'hbs');
var router = express.Router();
app.use(bodyParser.urlencoded({
extended: false
}));
app.use('/', router);
router.get('/', function(req, res) {
res.render('button-test');
});
router.get('/events', function(req,res){
var EventCard = models.EventCard;
EventCard.find({},function(err, cards){
console.log(err);
console.log(cards);
res.send(cards[0]);
})
})
//
// Things to Test:
// Make User
// Make Connection
// Make Potential Connection
// cardSchema
// IsConnected
// Potential Connection gets deleted on make connection and if denied event
router.get('/', function(req, res){
res.redirect('button-test')
})
// router.post('/makeUser', function(req, res){
// console.log(req.body)
// var user = new models.User({
// fname: req.body.fname,
// lname: req.body.lname,
// password: req.body.password,
// email: req.body.email
// // What is admin used for
// });
// user.save(function(err){
// if (err) {
// res.send(err)
// } else {
// res.send('User created')
// }
// })
// });
//
// router.post('/makeEvent', function(req, res){
// var eventCard = new models.EventCard({
// title: req.body.title,
// owner: req.body.userId,
// category: req.body.category,
// dateCreated: new Date(),
// eventStartTime: new Date(),
// eventEndTime: new Date(),
// location: req.body.location,
// usersAttending: []
// })
// eventCard.save(function(err){
// if (err) {
// res.send(err)
// } else {
// res.send('posted Event')
// }
// })
// })
//put this one on get 'event' after you test and done it
router.get('/getEvents', function(req, res) {
// console.log(req.query);
var sort = req.query.sort;
//Will eventually implement AJAX
var myId = req.user._id; //This would be req.user in practice
models.User.findById(myId).exec(function(err, user){
user.findSeenEvents(function(err, events){
models.EventCard.find({_id: {"$nin": events}})
.sort({sort: -1})
.limit(10)
.exec(
err, function(err, eventsQueue){
if (err) {
res.send(err)
} else {
console.log(eventsQueue);
res.send(eventsQueue)
} //Populate events deck on platform with a render in ajax/handlebars
});
})
})
})
//put this one on get 'event/:eventId' after you test and done it
router.get('/getEvents/:eventId', function(req, res){
EventCard.findById(req.param._id).exec(function(err, eventCard){
res.render(LAYOUT, {Images: eventCard.image})
})
})
//put this one on post 'notification' after you test and done it
router.post('/makeConnection', function(req, res){
//req.user?
var myId = req.user._id;
var theirId = req.param.theirId;
models.User.findById(myId).exec(function(err, user){
console.log(user)
user.makeConnection(theirId, function(err, connection){
res.send('connection made!');
})
})
})
//this is very similar to get notification, which show all notification for the owner
//so he knows which person like his event, and he can approve it.
//read more on my sections
router.post('/isConnected', function(req, res){
var myId = req.user._id;
var theirId = req.param.thierId;
models.User.findById(myId).exec(function(err, user){
user.isConnected(theirId, function(err, trueOrFalse){
if (err) res.send(err)
res.send(trueOrFalse);
})
})
})
app.listen(process.env.PORT || 3000);