Product Ratings, Grid Fix

This commit is contained in:
Ben PC
2022-03-30 09:56:33 +02:00
parent b4d97101d6
commit de99592f78
2 changed files with 64 additions and 50 deletions

View File

@@ -193,7 +193,7 @@ app.get("/search/:query",authNoRedirectHandler,(req, res) => {
user: req.user,
}
mysql_handler.con.query("SELECT *, (SELECT url FROM product_images i WHERE i.product_id = p.id LIMIT 1) as img FROM products p WHERE name LIKE ?;",["%"+query+"%"],function(err, result){
mysql_handler.con.query("SELECT *, (SELECT url FROM product_images i WHERE i.product_id = p.id LIMIT 1) as img, (SELECT AVG(rating) FROM reviews r WHERE r.productId = p.id) as rating FROM products p WHERE name LIKE ?;",["%"+query+"%"],function(err, result){
if(err) throw err;
dict.products = JSON.parse(JSON.stringify(result));