Skip to content

Commit

Permalink
included findtrip functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
shindigira committed Apr 6, 2016
1 parent 008e3d9 commit 2e136e2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
8 changes: 8 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ app.post('/data/trips/newtrip', function (req, res) {
}
});

app.post('/data/trips/findtrip', function (req, res) {
console.log("Post received!");
if (req.body) {
var client = new pg.Client(connectionString);
tripController.findTrip(req.body, req, res, client);
}
});

app.listen(port, function() {
console.log('App up and running on http://localhost: ', port);
userTableSure(connectionString);
Expand Down
35 changes: 34 additions & 1 deletion server/models/trips/tripController.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@ function newTrip(data, req, res, client) {
}); // end client.connect
}

function findTrip(data, req, res, client) {

var results = [];

var dataInputs = [
data.pickup_point,
data.dropoff_point,
data.depart_date, // "04/08/2016" string
];

client.connect(function(err) {
if(err) {
console.error('Post failed!');
return res.status(500).json({ success: false, data: err});
}

var query = client.query("SELECT FROM trips(pickup_point, dropoff_point, depart_date) values ($1, $2, $3)", dataInputs);

query.on('row', function(row) {
results.push(row);
});

query.on('end', function() {
client.end();
return res.status(202).sends({
results: results
});
});

}); // end client.connect
}

module.exports = {
newTrip: newTrip
newTrip: newTrip,
findTrip: findTrip
};

0 comments on commit 2e136e2

Please sign in to comment.