我在控制器文件上出现错误。 TypeError:无法读取未定义的属性“ then”
我的模型文件包含
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; }); } }
我的控制器文件包含
exports.checkIdsFromProducts = (request,response) => { let getData = request.body; var product_id = getData.product_id product.checkIds(product_id) .then(result => { console.log(result); }) }