diff --git a/src/controllers/addProduct.js b/src/controllers/addProduct.js index 95eac1e..43fd2ce 100644 --- a/src/controllers/addProduct.js +++ b/src/controllers/addProduct.js @@ -10,10 +10,23 @@ exports.post = (req, res) => { delete product.rating; delete product.comment; - // assign rating and comment to an object for passing to submitRating.js + // below I tried to isolate the problem and figured that this query might not do what it needs to do. + //The id always comes back as an empty array even with a productname that def. exists in the database + // let prodName = "Tofurky Feast"; + // prodName = "'" + prodName + "'"; + // console.log("prodname + quotes", prodName); + // getProductByName(prodName).then((id) => { + // console.log(id); + // } + // ) // Post the product & rating - postProduct(product).then(id => { + postProduct(product).then(() => { + let prodName = product.product_name; + prodName = "'" + prodName + "'"; + console.log("prodname + quotes", prodName); + getProductByName(prodName); + }).then(id => { const rating_comment = { rating: rating, comment: comment diff --git a/src/model/queries/getProductByName.js b/src/model/queries/getProductByName.js index 861947c..e76a209 100644 --- a/src/model/queries/getProductByName.js +++ b/src/model/queries/getProductByName.js @@ -1,6 +1,7 @@ const connection = require("../database/db_connection"); module.exports = product_name => { + console.log("prodname in sql", product_name); return connection.query("SELECT id FROM products WHERE product_name = $1", [ product_name ]);