I am getting error on controller file. TypeError: Cannot read property 'then' of undefined
My model file contains
function dbQuerynew(sql){ return new Promise( ( resolve, reject ) => { db.query(sql, (err, result) => { if (err) { return reject(err) } return resolve(result) }); }) } var Product = { checkIds: function(product_id){ var id_exist = 0; var sql = "SELECT mid FROM table WHERE product_id = '" + product_id + "'"; const results = dbQuerynew(sql) .then(results => { Promise.all(results.map(myId =>{ if(myId.mid === 46){ id_exist = 1; } })) }) .then(()=>{ return id_exist; }); } }
My Controller File contains
exports.checkIdsFromProducts = (request,response) => { let getData = request.body; var product_id = getData.product_id product.checkIds(product_id) .then(result => { console.log(result); }) }