0
Good morning guys, it looks simple but I haven’t been able to on my own and I haven’t found it on the net, I just wanted to return to view that fired Submit, I have a simple registration screen... then I launch the route -> controller -> model. in the controller has the validators, in case of error I wanted to return to the already filled dialog!! follows below the code snippets :
Route:
router.route('/cadastros').post(home.loggedIn, cadastrosController.salvaCadastro);
Controller:
exports.salvaCadastro = (req, res, next) => {
    let contract = new ValidationContract();
    contract.hasMinLen(req.body.nome_cadastros, 3, 'O nome deve conter pelo menos 3 caracteres');
    contract.isRequired(req.body.telefone1_cadastros, 'O telefone é obrigatório');
    contract.hasMinLen(req.body.telefone1_cadastros, 3, 'O telefone deve conter pelo menos 3 caracteres');
    // Se os dados forem inválidos
    if (!contract.isValid()) {
        req.flash('error', contract.errors());
        //req.flash('error', "Erro ao tentar pesquisar.", e);
        res.redirect('/cadastros');
        return;
    }
    modelCadastro.salvarCadastro(req.body)
        .then(idRegistro => {
            req.flash('success', 'Dados salvos com sucesso!');
         //   return false;
            return res.redirect('/cadastros');
        }).catch(e => {
            req.flash('error', "Erro ao tentar salvar os dados.", e);
            res.redirect('/cadastros');
      //      return false;
        });
}
If you need more information please ask!!! Thank you in advance, guys!!
At +