{"size": 1289, "ext": "js", "max_stars_repo_path": "libs/controllers/routeService.js", "max_stars_repo_name": "kelumkps/sg-travel-buddy-server", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "libs/controllers/routeService.js", "max_issues_repo_name": "kelumkps/sg-travel-buddy-server", "max_issues_repo_issues_event_min_datetime": "2016-03-06T12:30:59.000Z", "max_issues_repo_issues_event_max_datetime": "2016-05-23T08:39:06.000Z", "max_forks_repo_path": "libs/controllers/routeService.js", "max_forks_repo_name": "kelumkps/sg-travel-buddy-server", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 8, "max_forks_count": null, "avg_line_length": 36.8285714286, "max_line_length": 89, "alphanum_fraction": 0.5779674166}
var RouteModel = require('./../model/api/route');
var log = require('./../log')(module);

module.exports = {
    createRoute: function (route, callback) {
        var routeContent = {
            path: {
                type: 'LineString',
                coordinates: route.coordinates
            }
        };
        if (route.busStops) routeContent['busStops'] = route.busStops;
        if (route.userId) routeContent['userId'] = route.userId;
        if (route.distanceLimit) routeContent['distanceLimit'] = route.distanceLimit;

        var routeModel = new RouteModel(routeContent);
        routeModel.save(callback);
    },
    updateRoute: function (route, callback) {
        var conditions = {_id: route._id},
            options = {multi: false},
            update = {};
        if (route.coordinates) update['$push'] = {'path.coordinates': route.coordinates};
        if (route.busStops) update['$set'] = {busStops: route.busStops};

        if (update.$push || update.$set) {
            RouteModel.update(conditions, update, options, callback);
        } else {
            RouteModel.findById(route._id, '_id', callback);
        }
    },
    findRouteById: function (id, fields, callback) {
        RouteModel.findById(id, fields.split(',').join(' '), callback);
    }
};