This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Usage: Just include this script after Marionette and Handlebars loading | |
IF you use require.js add script to shim and describe it in the requirements | |
*/ | |
(function(Handlebars, Backbone) { | |
var Marionette = Backbone.Marionette; | |
Marionette.Handlebars = { | |
path: 'templates/', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Usage: Just include this script after Marionette and Handlebars loading | |
IF you use require.js add script to shim and describe it in the requirements | |
*/ | |
(function(Handlebars, Marionette) { | |
Marionette.Handlebars = { | |
path: 'templates/', | |
extension: '.handlebars' | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.delete('/api/friends/:_id', function (req, res){ | |
return Friends.findById(req.params._id, function (err, friend) { | |
return friend.remove(function (err) { | |
if (!err) { | |
console.log("Friend removed"); | |
return res.send(''); | |
} else { | |
console.log(err); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.put('/api/friends/:_id', function (req, res){ | |
return Friends.findById(req.params._id, function (err, friend) { | |
friend.name = req.body.name; | |
return friend.save(function (err) { | |
if (!err) { | |
console.log("updated friend"); | |
} else { | |
console.log(err); | |
} | |
return res.send(friend); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post('/api/friends', function(req, res,next){ | |
new_friend = new Friends({ name: req.body.name,user_id: req.currentUser.id }); | |
new_friend.save(); | |
res.send(new_friend); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/api/friends/:_id',function(req,res,next){ | |
Friends.findOne({ '_id': req.params._id , user_id: req.currentUser.id}) | |
.exec(function (err, friend_list) { | |
if (err) { | |
return next(err); | |
} | |
if (friend_list) { | |
res.send(friend_list); | |
} else { | |
return next(new NotFound('Could not find any such Friend')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/api/friends', function(req,res,next){ | |
Friends.find({user_id: req.currentUser.id }).exec(function (err, friend_list) { | |
if (err) { | |
return next(err); | |
} | |
if (friend_list) { | |
res.send(friend_list); | |
} else { | |
return next(new NotFound('Could not find any such Friend')); | |
} |