forked from jherrick/361-proj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
listings.js
66 lines (58 loc) · 1.64 KB
/
listings.js
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module.exports = function(){
var express = require('express');
var router = express.Router();
function getListing(res, mysql, context, id, complete){
var sql = 'SELECT * FROM properties WHERE id = ?'
var inserts = [id];
mysql.pool.query(sql, inserts, function(err, results, fields){
if(err){
res.write(JSON.stringify(err));
res.end();
}
context.listings = results;
complete();
});
}
/*
// Listings Routes
router.get('/', function(req, res){
var context = {};
callbackCount = 0;
var mysql = req.app.get('mysql');
getListings(res, mysql, context, complete);
function complete(){
callbackCount++;
if(callbackCount >= 1){
res.render('view-listings', context);
}
}
});*/
router.get('/:id', function(req, res){
callbackCount = 0;
var context = {};
var mysql = req.app.get('mysql');
getListing(res, mysql, context, req.params.id, complete);
function complete(){
callbackCount++;
if(callbackCount >= 1){
res.render('listings', context);
}
}
});
/* router.post('/', function(req, res){
//console.log(req.body)
var mysql = req.app.get('mysql');
var sql = "INSERT INTO () VALUES (?,?,?,?)";
var inserts = [req.body., req.body., req.body., req.body.];
sql = mysql.pool.query(sql,inserts,function(error, results, fields){
if(error){
console.log(JSON.stringify(error))
res.write(JSON.stringify(error));
res.end();
}else{
res.redirect('/view-listings');
}
});
}); */
return router;
}();