-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchBar.js
More file actions
27 lines (25 loc) · 1004 Bytes
/
Copy pathSearchBar.js
File metadata and controls
27 lines (25 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module.exports = function(){
var express = require('express');
var router = express.Router();
router.post('/', function(req, res){
if (!req.session.loggedin){
console.log("User is not logged in");
res.status(200).render('LoginPage');
return;
}
console.log("Search request received");
var mysql = req.app.get('mysql');
var sqlcommand = "SELECT cattery.name catteryName, cattery.id catteryId, user.id userID, user.username creatorName FROM (cattery LEFT JOIN user ON cattery.own_id=user.id) WHERE user.username='" + req.body.searchword + "' OR cattery.name='" + req.body.searchword + "'";
mysql.pool.query(sqlcommand, function(err, rows, fields){
if (err){
console.log(JSON.stringify(err))
res.write(JSON.stringify(err));
res.end();
return;
}
console.log(rows);
res.status(200).render('CatteriesPage', {catteryData: rows});
});
});
return router;
}();