forked from jherrick/361-proj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_prop.js
41 lines (34 loc) · 1008 Bytes
/
manage_prop.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
module.exports = function(){
var express = require('express');
var router = express.Router();
//function authenticates the user
function getListings(res, mysql, context, id, complete){
var sql = "SELECT * FROM users U INNER JOIN landlords_props LP ON U.user_id = LP.uid INNER JOIN properties P ON LP.pid = P.id WHERE U.user_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){
res.render('login');
});
router.post('/', function(req, res){
callbackCount = 0;
var context = {};
var mysql = req.app.get('mysql');
getListings(res, mysql, context, req.body.id, complete);
function complete(){
callbackCount++;
if(callbackCount >= 1){
res.render('manage_prop', context);
}
}
});
return router;
}();