Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. application.post('/noticias/salvar', [
  2. check('titulo','Título é obrigatório').not().isEmpty(),
  3. check('resumo','Resumo é obrigatório').not().isEmpty(),
  4. check('resumo','Resumo tem que ter entre 10 a 100 caracteres').isLength({ min: 10, max: 100 }),
  5. check('autor','Autor tem que ter entre 10 a 100 caracteres').isLength({ min: 10, max: 100 }),
  6. check('autor','Autor é obrigatório').not().isEmpty(),
  7. check('data_noticia','Data é obrigatório').not().isEmpty(),
  8. check('noticias','Noticia é obrigatória').not().isEmpty()
  9. ], (req, res) => {
  10. application.app.controllers.admin.noticias_salvar(req, res);
  11. });
  12.  
  13. module.exports.noticias_salvar = (req, res) => {
  14. let noticia = req.body
  15.  
  16. const errors = validationResult(req);
  17.  
  18. console.log(errors);
  19.  
  20. if(!errors.isEmpty()){
  21. return res.render('admin/form_add_noticia', { validacao: errors.array(), noticia: noticia });
  22. }
  23.  
  24. let conn = app.config.dbConnection();
  25. let noticiasModel = new app.app.models.NoticiasDAO(conn)
  26.  
  27. noticiasModel.salvarNoticia(noticia, (error, result) => {
  28. res.redirect('/noticias')
  29. });
  30. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement