Last active
August 30, 2015 15:13
-
-
Save ebourmalo/d02b0670987c64f8ebde to your computer and use it in GitHub Desktop.
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
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