i have a problem in my code: idols.js
router.post(
'/creating',
check('name', 'Min 1 and Max 50!').isLength({ min: 1, max: 50 }),
(req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
alertError = errors.array();
res.render('idols/create', {alertError});
}
else {
//Next if value is good
}
});
and idolsController.js
const idols = require('../models/idols');
class idolsController {
creating(req, res, next) {
const idols_data = new idols(req.body);
idols_data.save()
.then(() => res.redirect('/idols/edit'))
.catch(next());
}
module.exports = new idolsController;
my idols.js when not using logic validation
router.post('/creating', idolsController.creating);
--- My question: I want to convert the code in the 3rd paragraph to the code in the 1st paragraph (in this topic) thank for reading.
Your question is unclear. Please review and update