service.js
2.38 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
angular.module('focaAbmVehiculo')
.factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) {
var cisternas = [];
return {
getVehiculos: function() {
return $http.get(API_ENDPOINT.URL + '/vehiculo');
},
getVehiculo: function(id) {
return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id);
},
getTransportistas: function() {
return $http.get(API_ENDPOINT.URL + '/transportista');
},
guardarVehiculo: function(vehiculo) {
return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo});
},
deleteVehiculo: function(id) {
return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id);
},
getCisternas: function(idVehiculo) {
if(cisternas.length) {
return Promise.resolve(angular.copy(cisternas));
}else {
return new Promise(function(resolve, reject) {
$http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo)
.then(function(res) {
cisternas = res.data;
resolve(res.data);
});
});
}
},
guardarCisterna: function(cisterna, idx) {
if(idx != -1) {
//update
cisternas[idx] = cisterna;
}else {
//insert
cisternas.push(cisterna);
}
},
guardarCisternas: function(cisternas) {
return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas});
},
deleteCisterna: function(idx) {
cisternas[idx].desactivado = true;
},
cleanCisternas: function() {
cisternas = [];
},
getVehiculosPorTransportista: function(id) {
return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id);
},
getTransportistaPorId: function(id) {
return $http.get(API_ENDPOINT.URL + '/transportista/' + id);
},
transportistaSeleccionado: {}
};
}]);