diff --git a/routes/main.js b/routes/main.js index 82e5df1d5378a9c9515fd13c29c3d11258d9aeed..c28056447fb9e5fcf8a498a540f6a68f40792fca 100644 --- a/routes/main.js +++ b/routes/main.js @@ -3,6 +3,9 @@ const bcrypt = require('bcrypt'); const { json } = require('body-parser'); const { name } = require('ejs'); +const multer = require('multer'); +const upload = multer({storage: multer.memoryStorage()}); + //Module needed for the validator const { check, validationResult } = require('express-validator'); @@ -30,6 +33,13 @@ module.exports = function(app, shopData) { res.render('login.ejs', shopData) }); + + app.get('/itemlist',function(req,res){ + res.render('itemlist.ejs', shopData) + }); + + + app.get('/search-result',[check('name').isEmpty()],function (req, res) { @@ -51,6 +61,56 @@ module.exports = function(app, shopData) { }); + + app.post('/photoDB',upload.single("ProductImage"), (req,res) => { + + title = req.body.title; + product = req.body.name; + price = req.body.price; + info = req.body.info; + condition = req.body.condition; + image =req.file.buffer.toString("base64"); + + let sqlquery ="INSERT INTO items (title,name,price,info,condi,img) VALUES(?,?,?,?,?,?)"; + + let newListing = [req.sanitize(title),req.sanitize(product), + req.sanitize(price),req.sanitize(info), + req.sanitize(condition),req.sanitize(image)] + + db.query(sqlquery, newListing,(err, result) => { + if (err){ + return console.error(err.message); + } + else{ + let newData = Object.assign({}, shopData, {listingAdded: newListing}); + res.render("itemlisted.ejs", newData) + } + }); + + + }); + + + + + + + + + + + + + + + + + + + + + + app.get('/register', function (req,res) { res.render('register.ejs', shopData); });