return to view before executing the route.. nodejs

Asked

Viewed 67 times

0

Good afternoon guys how do I return to view that fired the route without executes it ?? follows below the passage...

 app.post('/atendimentos/pesquisa', home.loggedIn, function (req, res) {

    var nome_pesquisa = req.body.cliente_pesquisa;
    var placa_pesquisa = req.body.placa_pesquisa;
    var sinistro_pesquisa = req.body.sinistro_pesquisa;



    //--- AQUI É FEIO O TESTE DA CONDIÇÃO
    if (nome_pesquisa == '' && placa_pesquisa == '' && sinistro_pesquisa == '') {
        return; ///------- ASSIM NAO FUNCIONA!! COMO SERIA???
    }



    modelAtendimento.pesquisaPrincipalAtendimentos(nome_pesquisa, placa_pesquisa, sinistro_pesquisa).then(result => {

        res.render('atendimentospesquisa', {
            atendimentos: result,
            nomepesquisado: nome_pesquisa,
            placapesquisada: placa_pesquisa,
            sinistropesquisado: sinistro_pesquisa,
            results: true,
            layout: 'layout'
        });

    });

});

in case I haven’t been filled in any of the fields, I wish to return to view, even if possible send the message to her .....

obg, guys!!

  • I read your question now, I started using SO-pt a little while ago, what I know I try to help, in your case would help, but you already helped yourself kkkk.

  • I managed with the res.render() itself, I just couldn’t send an msg to the view yet

  • You can even improve by creating a middleware before running the route, data validation middleware. Send message to the view, explain better.

  • Opa valeu Anderson, la na view has a <div Alert> then when arriving return the message that must be filled , but I did so and ta working... follow... not being able to put code here as I do to put the tags for codes here in commentators??

  • Put the code between two grave accent.

  • Try to use the res.redirect(rota) before Return. Ex: res.redirect('/');

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.