Skip to content

Instantly share code, notes, and snippets.

@ebourmalo
Last active August 30, 2015 15:13
Show Gist options
  • Save ebourmalo/d02b0670987c64f8ebde to your computer and use it in GitHub Desktop.
Save ebourmalo/d02b0670987c64f8ebde to your computer and use it in GitHub Desktop.
module.exports = function(app) {
var resourcePath = '/api/questions';
app.use(resourcePath, auth.isAuthenticated, new MongooseService(Question));
app.service(resourcePath)
.before({
create: [setAuthor],
update: [updateLastActivityDate],
remove: [checkRemovePermissions],
addToCollection: [setAuthor]
}).after({
create: [notifyMentorsWithLabel],
addToCollection: [updateFollowers, notifyFollowers]
});
};
/**
* Set author (current user) for a new answer
*
* @param hook {Object} - Contains data about the hooked methods
* @param next {Function} - Callback to invoke when done
*/
function setAuthor(hook, next) {
if (hook.collection !== 'answers') {
return next();
}
var question = hook.data;
var user = hook.params.user;
question.author = user;
next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment