Commit 627cd1963fab7227a35d92cf62cbc8e6f02e30a5
1 parent
6ee3665d88
Exists in
master
fix guardar cisternas
Showing
1 changed file
with
1 additions
and
1 deletions
 
Show diff stats
src/js/service.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') | 
| 2 | .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 
| 3 | var cisternas = []; | 3 | var cisternas = []; | 
| 4 | return { | 4 | return { | 
| 5 | getVehiculos: function() { | 5 | getVehiculos: function() { | 
| 6 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); | 6 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); | 
| 7 | }, | 7 | }, | 
| 8 | getVehiculo: function(id) { | 8 | getVehiculo: function(id) { | 
| 9 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); | 9 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); | 
| 10 | }, | 10 | }, | 
| 11 | getTransportistas: function() { | 11 | getTransportistas: function() { | 
| 12 | return $http.get(API_ENDPOINT.URL + '/transportista'); | 12 | return $http.get(API_ENDPOINT.URL + '/transportista'); | 
| 13 | }, | 13 | }, | 
| 14 | guardarVehiculo: function(vehiculo) { | 14 | guardarVehiculo: function(vehiculo) { | 
| 15 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); | 15 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); | 
| 16 | }, | 16 | }, | 
| 17 | deleteVehiculo: function(id) { | 17 | deleteVehiculo: function(id) { | 
| 18 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); | 18 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); | 
| 19 | }, | 19 | }, | 
| 20 | getCisternas: function(idVehiculo) { | 20 | getCisternas: function(idVehiculo) { | 
| 21 | if(cisternas.length) { | 21 | if(cisternas.length) { | 
| 22 | return Promise.resolve(angular.copy(cisternas)); | 22 | return Promise.resolve(angular.copy(cisternas)); | 
| 23 | }else { | 23 | }else { | 
| 24 | return new Promise(function(resolve) { | 24 | return new Promise(function(resolve) { | 
| 25 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) | 25 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) | 
| 26 | .then(function(res) { | 26 | .then(function(res) { | 
| 27 | cisternas = res.data; | 27 | cisternas = res.data; | 
| 28 | resolve(res.data); | 28 | resolve(res.data); | 
| 29 | }); | 29 | }); | 
| 30 | }); | 30 | }); | 
| 31 | } | 31 | } | 
| 32 | }, | 32 | }, | 
| 33 | guardarCisterna: function(cisterna, idx) { | 33 | guardarCisterna: function(cisterna, idx) { | 
| 34 | if(idx !== -1) { | 34 | if(idx !== '-1') { | 
| 35 | //update | 35 | //update | 
| 36 | cisternas[idx] = cisterna; | 36 | cisternas[idx] = cisterna; | 
| 37 | }else { | 37 | }else { | 
| 38 | //insert | 38 | //insert | 
| 39 | cisternas.push(cisterna); | 39 | cisternas.push(cisterna); | 
| 40 | } | 40 | } | 
| 41 | }, | 41 | }, | 
| 42 | guardarCisternas: function(cisternas) { | 42 | guardarCisternas: function(cisternas) { | 
| 43 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); | 43 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); | 
| 44 | }, | 44 | }, | 
| 45 | deleteCisterna: function(idx) { | 45 | deleteCisterna: function(idx) { | 
| 46 | cisternas[idx].desactivado = true; | 46 | cisternas[idx].desactivado = true; | 
| 47 | }, | 47 | }, | 
| 48 | cleanCisternas: function() { | 48 | cleanCisternas: function() { | 
| 49 | cisternas = []; | 49 | cisternas = []; | 
| 50 | }, | 50 | }, | 
| 51 | getVehiculosPorTransportista: function(id) { | 51 | getVehiculosPorTransportista: function(id) { | 
| 52 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); | 52 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); | 
| 53 | }, | 53 | }, | 
| 54 | getTransportistaPorId: function(id) { | 54 | getTransportistaPorId: function(id) { | 
| 55 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); | 55 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); | 
| 56 | }, | 56 | }, | 
| 57 | transportistaSeleccionado: {} | 57 | transportistaSeleccionado: {} | 
| 58 | }; | 58 | }; | 
| 59 | }]); | 59 | }]); | 
| 60 | 60 |