-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·72 lines (61 loc) · 1.86 KB
/
app.js
File metadata and controls
executable file
·72 lines (61 loc) · 1.86 KB
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
67
68
69
70
71
72
var express = require ('express');
var mongoose = require ('mongoose');
var app = express();
// Here we find an appropriate database to connect to, defaulting to
// localhost if we don't find one.
var uristring = process.env.MONGOLAB_URI || process.env.MONGOHQ_URL || 'mongodb://localhost/lm';
mongoose.connect(uristring, function (err, res) {
if (err) {
console.log('ERROR connecting to: ' + uristring + '. ' + err);
}
else {
console.log('Succeeded connected to: ' + uristring);
mongoose.connection.db.collectionNames(function (err, names) {
console.log(names);
});
Schedule.find({}).count(function (err, result) {
console.log(result);
});
}
});
var scheduleSchema = new mongoose.Schema({
course: mongoose.Schema.Types.Mixed,
stop_code: String,
stop_id: String,
stop_name: String,
route_short_name: String,
trip_headsign: String,
direction: Number,
departure_time: String,
is_theorical: Number
});
var Schedule = mongoose.model('schedules', scheduleSchema);
app.get('/schedule/for/:parameter/:value', function (req, resp) {
var query = Schedule.find({});
query.where(req.params.parameter).equals(decodeURIComponent(req.params.value));
query.exec(function (err, result) {
resp.send(result);
});
});
app.get('/', function (req, resp) {
Schedule.findOne({}).exec(function (err, result) {
resp.send(result);
});
});
app.get('/count', function (req, resp) {
Schedule.find({}).count(function (err, result) {
resp.send(result.toString() + ' items in DB');
});
});
app.get('/schedule/at/:time', function (req, resp) {
var query = Schedule.find({});
console.log('here !');
query.where("departure_time").regex("06:59:40");
query.exec(function (err, result) {
resp.send(result);
});
});
var port = process.env.PORT || 9000;
app.listen(port, function() {
console.log("Listening on " + port);
});