-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtracker.js
More file actions
54 lines (50 loc) · 1.16 KB
/
tracker.js
File metadata and controls
54 lines (50 loc) · 1.16 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
var mongoose = require('mongoose');
module.exports = {
setup: function (callback){
mongoose.connect('mongodb://localhost/express');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function (){
var track = mongoose.Schema({
'lat': String,
'lng': String,
'empresa': String,
'retraso': Boolean,
'motorizado': String
});
this.Track = mongoose.model('Track', track);
if (callback){callback();}
}.bind(this));
},
track: function (empresa, retraso, motorizado, lat, lng){
var moto = new this.Track({
'lat': lat,
'lng': lng,
'retraso': retraso,
'empresa': empresa,
'motorizado': motorizado
});
console.log("save");
moto.save();
},
get_tracks: function (busqueda, callback) {
var q = {
'$or': [
{'empresa': busqueda},
{'motorizado': {
'$regex': '.*' + busqueda + '.*'
}}
]
};
this.Track.find(q, {}, function(err, raw){
raw.forEach(function (doc, index, raw) {
callback(doc);
});
});
},
delete_tracks: function (busqueda, callback) {
this.Track.remove(busqueda, function(err){
callback(err);
});
}
};