I have seen other similar questions, but they most seem to to suggest adding this
, but I get the error despite having this
:
When I run the code below I get:
TestDB.listOrgTests: Error: TypeError: Cannot read property 'listTests' of undefined
at /node/classes/TestDB.class.js:201:29
at new Promise (<anonymous>)
at TestDB.listOrgTests (/node/classes/TestDB.class.js:189:14)
at /node/index.js:116:22
at /node/index.js:118:6
at Layer.handle [as handle_request] (/node/node_modules/express/lib/router/layer.js:95:5)
at next (node/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/node/node_modules/express/lib/router/route.js:114:3)
class TestDB {
dbc = null;
constructor() {
console.log('new USerDB');
this.dbClass = require('./db.class');
this.db = new this.dbClass.db();
this.dbc = this.db.dbConn;
}
async listTests(sql, id) {
console.log('/listTests: ', id);
var dbc = this.dbc;
const ts = this.TestClass;
var ta = new Array();
return new Promise(async function(resolve, reject) {
try {
var values = [id];
dbc.query(sql,
values,
function(err, row) {
if (err) {
throw err;
}
console.log("TestDB.listTests: Queried ID: " + id + " " + row.length + " rows");
ta = [];
for (var i = 0; i < row.length; i++) {
// do Stuff
}
console.log('returned test array: ', ta);
return resolve(ta);
});
} catch (err) {
console.error("TestDB.listTests: Error: ", err);
return (reject);
}
})
}
async listOrgTests(orgID) {
console.log('/listOrgTests: ', orgID);
const ts = this.TestClass;
var ta = new Array();
return new Promise(async function(resolve, reject) {
const sql = `
SELECT *
FROM tests
WHERE org_id = ?
ORDER BY test_cdate DESC
`;
try {
ta = await this.listTests(sql, orgID);//<< ERROR HERE EVEN WITH this.
return resolve(ta);
} catch (err) {
console.error("TestDB.listOrgTests: Error: ", err);
return (reject);
}
})
}