aboutsummaryrefslogtreecommitdiff
path: root/server/routes
diff options
context:
space:
mode:
Diffstat (limited to 'server/routes')
-rw-r--r--server/routes/api.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/server/routes/api.js b/server/routes/api.js
index a0890a7..3e9c068 100644
--- a/server/routes/api.js
+++ b/server/routes/api.js
@@ -2,12 +2,24 @@ const express = require('express');
const router = express.Router();
const passport = require('passport');
-const exampleController = require('../controllers/example');
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();
+}
-router.get('/', exampleController.index);
-router.get('/protected', passport.authenticate('jwt', {session: false}), exampleController.index);
router.post('/register', userController.register);
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.delete('/products/:id', isAuth, isAdmin, productsController.destroy);
+
module.exports = router;