1
I need to pass the obtained data, by a query in the database, to my EJS template in order to manipulate these values.
My current code is like this
router.get('/devreport', redirectLogin, (req, res) => {
    //todo trocar o valor para o codigo do sg ao invés de 1. mockado para finalizar
    let cod_sg = 1;
    let heuristic_values = [];
    let selectQuery = `SELECT * 
                        FROM formulario
                        WHERE cod_sg = ?`
    let queryValues = [cod_sg];
    execSQLQuery(selectQuery, queryValues)
        .then(dbResponse => {
                heuristic_values.push({
                    values: dbResponse[0].heuristic_responses
                });            
            console.log(heuristic_values);
            res.render('../views/devreport.ejs', { heuristic_values });
        })
        .catch(error => {
            console.log(error);
            console.log(req.session.userId);
            res.json('fuck');
        });
    /* req.session.cod_sg = null; */
    res.render('../views/devreport.ejs');
});
Console result.log(heuristic_values);
[ { values: '{"likert-one": "strong_agree", "likert-six": "strong_agree", "likert-ten": "strong_disagree", "likert-two": "agree", "likert-five": "agree", "likert-four": "neutral", "likert-nine": "strong_agree", "likert-eight": "neutral", "likert-seven": "neutral", "likert-three": "strong_disagree", "likert-eleven": "agree", "likert-twelve": "strong_disagree", "likert-fifteen": "neutral", "likert-sixteen": "neutral", "likert-fourteen": "neutral", "likert-thirteen": "neutral", "likert-seventeen": "neutral"}' } ]
However, when I arrive at the page to which I rendered these values, I get the following return
ReferenceError: C:\Users\konex\Videos\ExpertSystem\views\devreport.ejs:14
    12| 
    13|     <ul>
 >> 14|             <%  const responses = heuristic_values %>
    15| 
    16|     </ul>
    17| 
heuristic_values is not defined
    at eval (eval at compile (C:\Users\konex\Videos\ExpertSystem\node_modules\ejs\lib\ejs.js:618:12), <anonymous>:11:27)
    at returnedFn (C:\Users\konex\Videos\ExpertSystem\node_modules\ejs\lib\ejs.js:653:17)
    at tryHandleCache (C:\Users\konex\Videos\ExpertSystem\node_modules\ejs\lib\ejs.js:251:36)
    at View.exports.renderFile [as engine] (C:\Users\konex\Videos\ExpertSystem\node_modules\ejs\lib\ejs.js:482:10)
    at View.render (C:\Users\konex\Videos\ExpertSystem\node_modules\express\lib\view.js:135:8)
    at tryRender (C:\Users\konex\Videos\ExpertSystem\node_modules\express\lib\application.js:640:10)
    at Function.render (C:\Users\konex\Videos\ExpertSystem\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (C:\Users\konex\Videos\ExpertSystem\node_modules\express\lib\response.js:1008:7)
    at router.get (C:\Users\konex\Videos\ExpertSystem\controllers\home_controller.js:248:9)
    at Layer.handle [as handle_request] (C:\Users\konex\Videos\ExpertSystem\node_modules\express\lib\router\layer.js:95:5)
						
Dude, I made the changes you requested and I’m still having the same problem. When placing <% const Sponses = Likert-one %>, the error updates to Likert is not defined
– Mateus Binatti
Guy was just an example, but do the following on the line you render the ejs,
res.render('../views/devreport.ejs', { heuristic_values });you change to
res.render('../views/devreport.ejs', { 'heuristic_values' : heuristic_values });, in your view you put<% const responses = heuristic_values %>now should work– Killdary Aguiar de Santana
Gee, man, I’d done just that :( Thanks so much for trying to help me out
– Mateus Binatti