diff --git a/index.js b/index.js index 3e002f0..21938af 100644 --- a/index.js +++ b/index.js @@ -113,15 +113,29 @@ function notAuthenticatedHandler(req, res, next){ app.get("/", authNoRedirectHandler, (req, res) => { mysql_handler.con.query("SELECT * FROM products", function(err, result){ if(err) throw err; - - let dict = { - title: "Startseite", - user: req.user, - products: JSON.parse(JSON.stringify(result)) - } - res.render('index', dict) + let products = JSON.parse(JSON.stringify(result)); + mysql_handler.con.query("SELECT * FROM product_images", function(err, result){ + if(err) throw err; + let dict = { + title: "Startseite", + user: req.user, + products: products, + product_images: JSON.parse(JSON.stringify(result)), + } + res.render('index', dict) + }) }); }); +app.get("/productImage/:productId", (req,res) => { + mysql_handler.con.query(`SELECT url FROM product_images WHERE product_id = ${req.params.productId} `,(err,result) =>{ + if (result.length > 0){ + res.redirect(JSON.parse(JSON.stringify(result))[0].url) + } + else { + res.redirect("/images/examples.jpg") + } + }) +}) // Account app.get("/account", authenticatedHandler, (req, res) => { diff --git a/views/index.ejs b/views/index.ejs index db077e7..1e375e4 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -1,103 +1,119 @@ -
- <%- include('partials/head'); %> + + + <%- include('partials/head'); %> - - <%- include('partials/header'); %> - -<%= products[i].name %>
- -
+ + <%= products[i].name %> +
+<%= products[randomNr].name %>
+<%= products[randomNr].name %>
+
-
','_self')">
-
-
','_self')">
-
-
','_self')">
-
- <%= products[randomNr].name %>
+
-
- <%= products[randomNr].name %>
+<%= products[randomNr].name %>
+