-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathio.js
More file actions
23 lines (21 loc) · 740 Bytes
/
io.js
File metadata and controls
23 lines (21 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var io = require('socket.io')();
var Spot = require('./models/spot');
io.on('connection', function(socket) {
socket.on('upvote', function(specialId) {
Spot.findOne({'specials._id': specialId}, function(err, spot) {
var special = spot.specials.id(specialId);
special.votes.upvotes++;
io.emit('vote-changed', special);
spot.save();
});
});
socket.on('downvote',function(specialId) {
Spot.findOne({'specials._id': specialId}, function(err, spot) {
var special = spot.specials.id(specialId);
special.votes.downvotes++;
io.emit('vote-changed', special);
spot.save();
});
});
});
module.exports = io;