diff options
author | Mateja <mail@matejamaric.com> | 2021-07-11 13:32:43 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2021-07-11 13:32:43 +0200 |
commit | 3fbd440fe39a2677a12c234f06aaa1bae6a197a4 (patch) | |
tree | b27e26d567a5e8106d597a84fd1d664e61a08cd8 /server/routes | |
parent | 54677c68f50b7c105a1f6cc5e9593877781fc8d6 (diff) | |
download | mevn-ecommerce-3fbd440fe39a2677a12c234f06aaa1bae6a197a4.tar.gz mevn-ecommerce-3fbd440fe39a2677a12c234f06aaa1bae6a197a4.zip |
Added Product routes, model and boilerplate controller.
Diffstat (limited to 'server/routes')
-rw-r--r-- | server/routes/api.js | 18 |
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; |