I am trying to write a simple check()
function following this example. The function successfully prints out "True!" but the return value of the function is undefined
when I do console.log(submitModels.verifyOrganizationString(formInputs.organizationString));
. How can I get the function to return true
and false
?
Right now the function only returns "Invalid organization string"
even when the string is valid.
I am thinking this result has to do with the pg-promise
library, but am not sure.
In the file submit.js
, I have:
function verifyOrganizationString(organizationString) {
db.one("select * from organizations where organization_string=$1", [organizationString])
.then(data => {
console.log("True!");
return true;
})
.catch(error => {
console.log("False!");
return false;
});
}
module.exports = {
verifyOrganizationString,
};
In another file, I have
const submitModels = require('../models/submit.js');
function proccessSubmission(req, res) {
var formInputs = req.body;
console.log(submitModels.verifyOrganizationString(formInputs.organizationString));
if (submitModels.verifyOrganizationString(formInputs.organizationString)) {
submitModels.insertIntoDatabase(formInputs);
res.redirect('/');
} else {
res.send("Invalid organization string");
}
}