-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const validateUserInput = (req, res, next) => { | ||
const { body } = req; | ||
/* if (null(body)) { | ||
return ( | ||
res.status(400).json('Hi! You\'d have to send something') | ||
); | ||
} */ | ||
if (!String(body.fullName)) { | ||
return ( | ||
res.status(400).json('The user\'s name has to be a string!') | ||
); | ||
} | ||
if (!String(body.emailAddress)) { | ||
return ( | ||
res.status(400).json('The user\'s email adress has to be a string!') | ||
); | ||
} | ||
if (body.password.length < 6) { | ||
return ( | ||
res.status(400).json('The user\'s password has to be more than 6 characters!') | ||
); | ||
} | ||
if (!body.type) { | ||
return ( | ||
res.status(400).json('There really has to be a type!') | ||
); | ||
} | ||
return next(); | ||
}; | ||
|
||
const validateProductInput = (req, res, next) => { | ||
const { body } = req; | ||
if (!body.name || !body.description || !body.price || !body.quantity) { | ||
return ( | ||
res.status(400).json('Hi! Some details are missing. Can you check and try again?') | ||
); | ||
} | ||
return next(); | ||
}; | ||
|
||
const validateSaleInput = (req, res, next) => { | ||
const { body } = req; | ||
if (!body.productName || !body.price || !body.quantity) { | ||
return ( | ||
res.status(400).json('Hi! Some details are missing. Can you check and try again?') | ||
); | ||
} | ||
return next(); | ||
}; | ||
|
||
export { validateUserInput, validateProductInput, validateSaleInput }; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
import express from 'express'; | ||
import { | ||
getAllSales, getOneSale, addSale, | ||
} from '../controllers/salesController'; | ||
import { | ||
getAllProducts, getOneProduct, addProduct, | ||
} from '../controllers/productsController'; | ||
import { | ||
getAllSales, getOneSale, addSale, | ||
} from '../controllers/salesController'; | ||
import { | ||
getAllUsers, getOneUser, addUser, loginUser, | ||
} from '../controllers/usersController'; | ||
import { authenticate, verifyAdmin, verifyAttendant } from '../middleware/verify'; | ||
import { | ||
validateUserInput, validateProductInput, validateSaleInput, | ||
} from '../middleware/validateinput'; | ||
|
||
const router = express.Router(); | ||
|
||
/* GET home page. */ | ||
/* router.get('/', (req, res, next) => { | ||
res.send('index.html'); | ||
}); */ | ||
}); */ | ||
|
||
/* Products Router */ | ||
router.get('/products', authenticate, getAllProducts); | ||
router.get('/products/:id', authenticate, getOneProduct); | ||
router.post('/products', authenticate, verifyAdmin, addProduct); | ||
router.post('/products', authenticate, verifyAdmin, validateProductInput, addProduct); | ||
|
||
/* Sales Router */ | ||
router.get('/sales', authenticate, verifyAdmin, getAllSales); | ||
router.get('/sales/:id', authenticate, getOneSale); | ||
router.post('/sales', authenticate, verifyAttendant, addSale); | ||
router.get('/sales/:id', authenticate, verifyAdmin, getOneSale); | ||
router.post('/sales', authenticate, verifyAttendant, validateSaleInput, addSale); | ||
|
||
/* Users Router */ | ||
router.get('/users', authenticate, verifyAdmin, getAllUsers); | ||
router.get('/users/:id', authenticate, verifyAdmin, getOneUser); | ||
router.post('/users', authenticate, verifyAdmin, addUser); | ||
router.post('/users', authenticate, verifyAdmin, validateUserInput, addUser); | ||
router.post('/login', loginUser); | ||
|
||
export default router; |
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
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