Hello guys,
The developer I work with have been stuck with this issue for few days now and I need help from someone experienced in js to answer this. I have of course changed the names of the things so it doesn’t compromise any security in the platform, code is very similar tho.
sample.js code thats causing the issue:
const getColourById = async (req, res) => {
let id = req.query["id"]
let strength = null;
let colour = null;
client.query(`SELECT * FROM colours_strength_table WHERE id == ${id}`,
function(err, result) {
for (let r in rows) {
if (r["id"] === id) {
strength = r["strength"]
colour = r["colour"]
}
}
})
if (strength === null && colour === null) { return res.json("success": false)}
return res.json({
outputs: [
{ strength: strength, colour: colour}
]
})
}
Issue being raised in Terminal:
sample.js:518
for (let r in rows) {
^
ReferenceError: rows is not defined
at Query.callback (/home/dev/project/node/lib/apps/sample.js:518:16)
at Query.handleError (/home/dev/project/node/node_modules/pg/lib/query.js:128:19)
at Client._handleErrorMessage (/home/dev/project/node/node_modules/pg/lib/client.js:335:17)
at Connection.emit (events.js:314:20)
at /home/dev/project/node/node_modules/pg/lib/connection.js:114:12
at Parser.parse (/home/dev/project/node/node_modules/pg-protocol/dist/parser.js:40:17)
at Socket.<anonymous> (/home/dev/project/node/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:272:9)
error Command failed with exit code 1.
info Visit
https://yarnpkg.com/en/docs/cli/run for documentation about this command.