diff --git a/functions/index.js b/functions/index.js index 20f73a9..0d54a13 100644 --- a/functions/index.js +++ b/functions/index.js @@ -35,9 +35,9 @@ app.get("/home", function(request, responce) { function homePage(request, responce) { var dbRef = database.ref("/products") - dbRef.limitToLast(5).once('value', function(snapshot){ + dbRef.orderByChild("status").equalTo("on-sale").limitToLast(5).once('value', function(snapshot){ var data = {} - data = snapshot.val() + if (snapshot.val()) {data = snapshot.val()} var x = "none" if (request.query.itemAdded == "true") { x = 'block' @@ -96,6 +96,27 @@ app.get('/my-products', function(request, responce){ } }) +app.get('/my-product', function(request, responce){ + if (request.query.uToken && request.query.productid) { + admin.auth().verifyIdToken(request.query.uToken) + .then(function(decodedToken) { + let uid = decodedToken.uid; + var dbRef = database.ref("/products/"+request.query.productid) + dbRef.once('value', function(snapshot){ + data = snapshot.val() + responce.render('my-product.ejs', {item:data, key:request.query.productid}) + }) + }) + .catch(function(error) { + console.log(error) + responce.send("
<%= products[key].name%>
- <% var publicField %> - <% if (products[key].public == "") {publicField = "On sale"} else {publicField = "Hidden"}%> -<%= publicField%>
+<%= products[key].status%>
<%= products[key].location%>
£ <%= products[key].price%>