I'm getting a pretty standard error that I should be able to figure out but I am stuck like chuck ATM:
first_query(): TypeError: ind_promise is not a function
I have simplified the code down to its very basic core components and I cannot shake this error.
router.get('/:cusId/email/start', auth.check, async (req, res) => {
try {
let cus_id = req.params.cusId;
const pool = await poolPromise;
let query;
let request;
query = ("SELECT (CUS_FIRST_NAME + ' ' + CUS_LAST_NAME) AS CUS_NAME, CUS_IND_ID FROM CUS WHERE CUS_STATUS = 'A' AND CUS_ID = @CUS_ID");
request = pool.request()
.input('CUS_ID', sql.Int, cus_id);
std.first_query(request, query)
.then(async function(cus_rec) {
let ind_promise = new Promise ((resolve, reject) => {
resolve (1);
});
ind_promise()
.then((ind_id) => {
console.log(ind_id);
})
.catch((err) => {
console.log('ind_promise(): ' + err.message);
res.status(500);
res.send(err.message)
});
})
.catch (function(err) {
console.log('first_query(): ' + err);
res.status(500);
res.send(err.message)
});
} catch {
console.log(err.message);
res.status(500);
res.send(err.message)
}
});
This is more than a little irritating as I am not new to promises. I know I am doing something very stupid but it's not obvious. Experts, please help.
You called your promise right away and then you tried to invoke it like its a function
let ind_promise = new Promise ((resolve, reject) => {resolve (1);});
ind_promise()
Either change ind_promise
to be a function, or call it without invoking it ind_promise.then