diff options
Diffstat (limited to 'server/routes')
-rw-r--r-- | server/routes/api.js | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/server/routes/api.js b/server/routes/api.js index 3e9c068..33885c9 100644 --- a/server/routes/api.js +++ b/server/routes/api.js @@ -1,16 +1,10 @@ const express = require('express'); const router = express.Router(); -const passport = require('passport'); const userController = require('../controllers/user'); const productsController = require('../controllers/products'); -const isAuth = passport.authenticate('jwt', {session: false}); -const isAdmin = (req, res, next) => { - if (!req.user.admin) - res.status(401).json({status: "You need to be an administrator!"}); - else next(); -} +const {isAuth, isAdmin, upload} = require('../lib/middleware'); router.post('/register', userController.register); router.post('/login', userController.login); @@ -18,8 +12,8 @@ router.post('/login', userController.login); router.get('/products', productsController.index); router.get('/products/:id', productsController.show); -router.post('/products', isAuth, isAdmin, productsController.store); -router.patch('/products/:id', isAuth, isAdmin, productsController.update); +router.post('/products', isAuth, isAdmin, upload.single('image'), productsController.store); +router.patch('/products/:id', isAuth, isAdmin, upload.single('image'), productsController.update); router.delete('/products/:id', isAuth, isAdmin, productsController.destroy); module.exports = router; |