Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- application.post('/noticias/salvar', [
- check('titulo','Título é obrigatório').not().isEmpty(),
- check('resumo','Resumo é obrigatório').not().isEmpty(),
- check('resumo','Resumo tem que ter entre 10 a 100 caracteres').isLength({ min: 10, max: 100 }),
- check('autor','Autor tem que ter entre 10 a 100 caracteres').isLength({ min: 10, max: 100 }),
- check('autor','Autor é obrigatório').not().isEmpty(),
- check('data_noticia','Data é obrigatório').not().isEmpty(),
- check('noticias','Noticia é obrigatória').not().isEmpty()
- ], (req, res) => {
- application.app.controllers.admin.noticias_salvar(req, res);
- });
- module.exports.noticias_salvar = (req, res) => {
- let noticia = req.body
- const errors = validationResult(req);
- console.log(errors);
- if(!errors.isEmpty()){
- return res.render('admin/form_add_noticia', { validacao: errors.array(), noticia: noticia });
- }
- let conn = app.config.dbConnection();
- let noticiasModel = new app.app.models.NoticiasDAO(conn)
- noticiasModel.salvarNoticia(noticia, (error, result) => {
- res.redirect('/noticias')
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement