ride-data-store
Version:
ridematching transport logistics database
49 lines (47 loc) • 1.2 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
module.exports = function(http, url) {
var find;
if (!url) {
url = "";
}
return {
save: function(ride, cb) {
return http.post(url, {
body: JSON.stringify(ride)
}, function(err, res, body) {
return cb(JSON.parse(body));
});
},
get: function(id, cb) {
return http.get(url + ("/rides/" + id), function(err, res, body) {
console.log(body);
return cb(JSON.parse(body));
});
},
find: find = function(query, cb) {
var route;
if (query.from && query.to) {
route = "/" + query.from + "/" + query.to;
if (query.time) {
route += "?time=" + query.time;
}
if (query.type) {
route += "?type=" + query.type;
}
return cb(http.get(url + route));
} else {
return cb({
on: function(what, fun) {
if (what === "end") {
return fun();
} else {
return this;
}
}
});
}
}
};
};
}).call(this);