{"size": 2456, "ext": "js", "max_stars_repo_path": "app/Services/TripsService.js", "max_stars_repo_name": "MTretowski/FrontEnd", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/Services/TripsService.js", "max_issues_repo_name": "MTretowski/FrontEnd", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/Services/TripsService.js", "max_forks_repo_name": "MTretowski/FrontEnd", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 38.9841269841, "max_line_length": 230, "alphanum_fraction": 0.5810260586}
app.service('tripsService', function ($rootScope, tripRESTService) {

    this.getTrips = function () {
        tripRESTService.getTrips();
    };

    $rootScope.$on('gotTripsFromDatabase', function (event, trips) {
        for (let i = trips.length - 1; i >= 0; i--) {
            trips[i].startDate = new Date(trips[i].startDate);
            trips[i].endDate = new Date(trips[i].endDate);
        }
        $rootScope.$broadcast('updateTrips', trips);
    });

    this.addTrip = function (businessTripNumber, startDate, endDate, distance, usedFuelCan, usedFuelWebasto, fuelConsumptionByGps, realFuelConsumption,
                             comment, vehicleId, driverId, startingMeasurmentId, endingMeasurmentId) {

        tripRESTService.addTrip(
            {
                'businessTripNumber': businessTripNumber,
                'startDate': startDate,
                'endDate': endDate,
                'distance': distance,
                'usedFuelCan': usedFuelCan,
                'usedFuelWebasto': usedFuelWebasto,
                'fuelConsumptionByGps': fuelConsumptionByGps,
                'realFuelConsumption': realFuelConsumption,
                'comment': comment,
                'vehicleId': vehicleId,
                'driverId': driverId,
                'startingMeasurmentId': startingMeasurmentId,
                'endingMeasurmentId': endingMeasurmentId
            })

    };

    this.editTrip = function (id, businessTripNumber, startDate, endDate, distance, usedFuelCan, usedFuelWebasto, fuelConsumptionByGps, realFuelConsumption, comment, vehicleId, driverId, startingMeasurmentId, endingMeasurmentId) {

        tripRESTService.editTrip(
            {
                'id': id,
                'businessTripNumber': businessTripNumber,
                'startDate': startDate,
                'endDate': endDate,
                'distance': distance,
                'usedFuelCan': usedFuelCan,
                'usedFuelWebasto': usedFuelWebasto,
                'fuelConsumptionByGps': fuelConsumptionByGps,
                'realFuelConsumption': realFuelConsumption,
                'comment': comment,
                'vehicleId': vehicleId,
                'driverId': driverId,
                'startingMeasurmentId': startingMeasurmentId,
                'endingMeasurmentId': endingMeasurmentId
            })

    };

    this.deleteTrip = function (id) {
        tripRESTService.deleteTrip(id);
    }

});