forked from linnovate/mean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
articles.js
26 lines (20 loc) · 877 Bytes
/
articles.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
'use strict';
// Articles routes use articles controller
var articles = require('../controllers/articles');
var authorization = require('./middlewares/authorization');
// Article authorization helpers
var hasAuthorization = function(req, res, next) {
if (req.article.user.id !== req.user.id) {
return res.send(401, 'User is not authorized');
}
next();
};
module.exports = function(app) {
app.get('/articles', articles.all);
app.post('/articles', authorization.requiresLogin, articles.create);
app.get('/articles/:articleId', articles.show);
app.put('/articles/:articleId', authorization.requiresLogin, hasAuthorization, articles.update);
app.del('/articles/:articleId', authorization.requiresLogin, hasAuthorization, articles.destroy);
// Finish with setting up the articleId param
app.param('articleId', articles.article);
};